0% found this document useful (0 votes)
5 views3 pages

MySQL Complete Basic Commands CheatSheet

This cheat sheet provides essential MySQL commands for creating and managing databases, including creating tables, inserting and retrieving data, filtering results, and using aggregate functions. It also covers updating and deleting data, altering tables, renaming tables, joining tables, and sorting results. Additionally, it includes commands for creating and using databases, showing tables, and applying limits and aliases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

MySQL Complete Basic Commands CheatSheet

This cheat sheet provides essential MySQL commands for creating and managing databases, including creating tables, inserting and retrieving data, filtering results, and using aggregate functions. It also covers updating and deleting data, altering tables, renaming tables, joining tables, and sorting results. Additionally, it includes commands for creating and using databases, showing tables, and applying limits and aliases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Basic MySQL Commands Cheat Sheet

1. Create Table

CREATE TABLE students (


id INT PRIMARY KEY,
name VARCHAR(100),
age INT,
grade CHAR(1)
);

2. Insert Data

INSERT INTO students (id, name, age, grade)


VALUES (1, 'Amit', 16, 'A'),
(2, 'Priya', 17, 'B');

3. Retrieve Data

SELECT * FROM students;


SELECT name, age FROM students;

4. Filtering with WHERE

SELECT * FROM students WHERE grade = 'A';


SELECT * FROM students WHERE age > 16;
SELECT * FROM students WHERE age BETWEEN 15 AND 18;
SELECT * FROM students WHERE name LIKE 'A%';

5. Logical Operators

SELECT * FROM students WHERE grade = 'A' AND age > 15;
SELECT * FROM students WHERE grade = 'A' OR grade = 'B';

6. Aggregate Functions

SELECT COUNT(*) FROM students;


SELECT MAX(age) FROM students;
Basic MySQL Commands Cheat Sheet

SELECT MIN(age) FROM students;


SELECT AVG(age) FROM students;
SELECT SUM(age) FROM students;

7. Grouping Data

SELECT grade, COUNT(*) FROM students GROUP BY grade;

8. Having Clause

SELECT grade, COUNT(*) FROM students


GROUP BY grade
HAVING COUNT(*) > 1;

9. Update Data

UPDATE students SET grade = 'A' WHERE id = 2;

10. Delete Data

DELETE FROM students WHERE id = 1;

11. Alter Table

ALTER TABLE students ADD email VARCHAR(100);


ALTER TABLE students MODIFY grade VARCHAR(2);
ALTER TABLE students DROP COLUMN email;

12. Rename Table

RENAME TABLE students TO school_students;

13. Distinct Values

SELECT DISTINCT grade FROM school_students;


Basic MySQL Commands Cheat Sheet

14. Join Tables

-- Assuming a 'teachers' table with subject column


SELECT s.name, t.name
FROM school_students s
JOIN teachers t ON s.subject = t.subject;

15. Drop Table

DROP TABLE teachers;

16. Create and Use Database

CREATE DATABASE school;


USE school;

17. Show Tables & Describe

SHOW TABLES;
DESCRIBE school_students;

18. Sorting Results

SELECT * FROM school_students ORDER BY age ASC;


SELECT * FROM school_students ORDER BY name DESC;

19. LIMIT Clause

SELECT * FROM school_students LIMIT 5;

20. Aliases

SELECT name AS StudentName, grade AS GradeReceived FROM school_students;

You might also like