# SQL Query Cheat Sheet

## Basic SELECT

```sql
SELECT column1, column2 FROM table_name;
SELECT * FROM table_name WHERE condition;
SELECT DISTINCT column1 FROM table_name;
SELECT column1 FROM table_name ORDER BY column1 DESC;
SELECT column1 FROM table_name LIMIT 10;
```

## Filtering

```sql
WHERE column1 = 'value'
WHERE column1 > 100
WHERE column1 BETWEEN 10 AND 20
WHERE column1 IN ('a', 'b', 'c')
WHERE column1 LIKE '%pattern%'
WHERE column1 IS NULL
```

## Joins

```sql
-- Only matching rows in both tables
SELECT * FROM a INNER JOIN b ON a.id = b.a_id;

-- All rows from left table, matched rows from right
SELECT * FROM a LEFT JOIN b ON a.id = b.a_id;

-- All rows from both tables
SELECT * FROM a FULL OUTER JOIN b ON a.id = b.a_id;
```

## Aggregation

```sql
SELECT category, COUNT(*) FROM products GROUP BY category;
SELECT category, AVG(price) FROM products GROUP BY category HAVING AVG(price) > 100;
SELECT COUNT(*), SUM(amount), AVG(amount), MIN(amount), MAX(amount) FROM orders;
```

## Modifying Data

```sql
INSERT INTO table_name (col1, col2) VALUES ('a', 'b');
UPDATE table_name SET col1 = 'new_value' WHERE id = 1;
DELETE FROM table_name WHERE id = 1;
```

## Common Mistakes

- WHERE ကို aggregate function (COUNT, AVG) နဲ့ filter မလုပ်ရ — HAVING ကို သုံးပါ
- UPDATE/DELETE ကို WHERE မပါဘဲ run ရင် row အားလုံး ပြောင်း/ဖျက်ပါလိမ့်မယ် — run ခင် WHERE clause ကို double-check ပါ
