Welcome to

Sara's SQL Trainer

You're going to crush this! Let's go ๐Ÿ’ช

๐Ÿ—ƒ๏ธ

Your Tables

๐ŸŽฏ

Your Mission

๐Ÿ’ผ Why is this useful?

โœจ Target Result


                        
๐Ÿ’ป

Write Your Magic Query

๐Ÿ“Š

Your Amazing Result

๐Ÿ“–

Your SQL Toolkit

Keep this handy!

SELECT

Select columns from a table

SELECT name FROM users SELECT * FROM products -- * means all columns

WHERE

Filter rows with conditions

WHERE price > 100 WHERE name = 'Alice' WHERE name LIKE 'A%'

ORDER BY

Sort results

ORDER BY name ASC ORDER BY price DESC

๐Ÿ”— JOIN Types

Combine data from multiple tables

INNER JOIN

Returns only matching rows from both tables

SELECT * FROM A INNER JOIN B ON A.id = B.a_id

LEFT JOIN

All rows from left table + matching from right

SELECT * FROM A LEFT JOIN B ON A.id = B.a_id

RIGHT JOIN

All rows from right table + matching from left

SELECT * FROM A RIGHT JOIN B ON A.id = B.a_id

FULL OUTER JOIN

All rows from both tables

SELECT * FROM A FULL OUTER JOIN B ON A.id = B.a_id

GROUP BY

Group for aggregation

GROUP BY department HAVING COUNT(*) > 2

Aggregate

Calculate values

COUNT(*), SUM(col) AVG(col), MIN(col)
โš ๏ธ

Common Mistakes to Avoid

โŒ Missing Quotes

Strings need single quotes

WHERE name = Alice WHERE name = 'Alice'

โŒ WHERE + Aggregate

Use HAVING, not WHERE for groups

WHERE COUNT(*) > 2 HAVING COUNT(*) > 2

โŒ SELECT not in GROUP BY

Only select grouped or aggregate cols

SELECT name, dept GROUP BY dept SELECT dept, COUNT(*) GROUP BY dept

โŒ JOIN without ON

JOIN needs ON to connect tables

SELECT * FROM orders JOIN customers JOIN customers ON orders.cust_id = customers.id

โŒ Missing Table Name

FROM needs a table name

SELECT * FROM SELECT * FROM employees

โŒ Typos in Keywords

Check spelling carefully

SELEC * FROM table SELECT * FROM table

โŒ ORDER BY Position

ORDER BY comes after GROUP BY

ORDER BY col GROUP BY col2 GROUP BY col2 ORDER BY col

โŒ LIKE with =

Use LIKE for patterns

WHERE name = 'A%' WHERE name LIKE 'A%'