HomeCheat SheetsSQL Queries & Joins Cheat Sheet
100% Client-Side β€’ 0 B Data Leaves Browser
database

SQL Queries & Joins Cheat Sheet

Comprehensive guide to SQL queries, table joins (INNER, LEFT, RIGHT, FULL), grouping, aggregations, and subqueries.

Querying & Filtering

Fetch latest 10 active usersSELECT * FROM users WHERE status = "active" ORDER BY created_at DESC LIMIT 10;
Return unique values without duplicatesSELECT DISTINCT country FROM customers;
Range and list filteringSELECT * FROM products WHERE price BETWEEN 10 AND 50 AND category IN ("tech", "dev");
Aggregate calculations grouped by departmentSELECT COUNT(*), AVG(salary), MAX(salary) FROM employees GROUP BY department_id;

Table Joins

INNER JOIN: Returns rows when matching keys exist in both tablesSELECT u.name, o.total FROM users u INNER JOIN orders o ON u.id = o.user_id;
LEFT JOIN: Returns all users, plus matching orders if they existSELECT u.name, o.total FROM users u LEFT JOIN orders o ON u.id = o.user_id;

Frequently Asked Questions

β€’ What is the difference between WHERE and HAVING in SQL?

WHERE filters rows before any groupings or aggregations are calculated, while HAVING filters grouped rows after GROUP BY aggregations.