Here’s a quick SQL cheat sheet to help with common tasks:
SELECT * FROM table_name;
SELECT column1, column2 FROM table_name;
SELECT * FROM table_name WHERE condition;
SELECT * FROM table_name ORDER BY column1 ASC|DESC;
SELECT * FROM table_name LIMIT number;
SELECT COUNT(*) FROM table_name;
SELECT SUM(column_name) FROM table_name;
SELECT AVG(column_name) FROM table_name;
SELECT MIN(column_name) FROM table_name;
SELECT MAX(column_name) FROM table_name;
SELECT column_name, COUNT(*) FROM table_name GROUP BY column_name;
SELECT column_name, COUNT(*) FROM table_name GROUP BY column_name HAVING COUNT(*) > value;
SELECT columns FROM table1 INNER JOIN table2 ON table1.column = table2.column;
SELECT columns FROM table1 LEFT JOIN table2 ON table1.column = table2.column;
SELECT columns FROM table1 RIGHT JOIN table2 ON table1.column = table2.column;
SELECT columns FROM table1 FULL JOIN table2 ON table1.column = table2.column;
SELECT column1, (SELECT column2 FROM table2 WHERE condition) AS alias FROM table1;
SELECT column1 FROM table1 WHERE column2 = (SELECT column2 FROM table2 WHERE condition);
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
UPDATE table_name SET column1 = value1 WHERE condition;
DELETE FROM table_name WHERE condition;
CREATE TABLE table_name (
column1 datatype constraints,
column2 datatype constraints
);
DROP TABLE table_name;
ALTER TABLE table_name ADD column_name datatype;
ALTER TABLE table_name DROP COLUMN column_name;
This should cover most of the basic and intermediate SQL tasks. Let me know if you need anything more specific!