Skip to content

SQL Quick Reference (Cheat Sheet) πŸ“„

Mentor's Note: Keep this page bookmarked! It contains the "Formula" for every major SQL command we've learned. πŸ’‘


πŸ—οΈ Structure (DDL)

Action Syntax
Create Table CREATE TABLE table (col type, ...);
Add Column ALTER TABLE table ADD col type;
Drop Column ALTER TABLE table DROP COLUMN col;
Delete Table DROP TABLE table;
Clear Table TRUNCATE TABLE table;

πŸ“ Data Operations (DML)

Action Syntax
Fetch All SELECT * FROM table;
Add Row INSERT INTO table (cols) VALUES (vals);
Modify Row UPDATE table SET col = val WHERE condition;
Remove Row DELETE FROM table WHERE condition;

πŸ” Filtering & Sorting

Filter Logic
Range WHERE salary BETWEEN 1000 AND 5000
Set WHERE city IN ('Surat', 'Mumbai')
Pattern WHERE name LIKE 'A%'
NULLs WHERE email IS NULL
Sort ORDER BY name ASC|DESC

πŸ•ΈοΈ Joins

Join Type Description
INNER JOIN Match in BOTH tables. βœ…
LEFT JOIN ALL from Left + Matches from Right. πŸ‘ˆ
FULL JOIN EVERYTHING from both. πŸŒ•

πŸ“Š Aggregates

  • COUNT(*): Total Rows.
  • SUM(col): Total Sum.
  • AVG(col): Mean.
  • MIN/MAX: Smallest/Largest.

πŸ’‘ Syntax Hierarchy

  1. SELECT
  2. FROM
  3. WHERE
  4. GROUP BY
  5. HAVING
  6. ORDER BY

πŸ“ˆ Learning Path