DQL Guide Obsidian
DQL Guide Obsidian
SELECT Statement
Syntax:
Examples:
2. WHERE Clause
Syntax:
Examples:
Filter by value:
SELECT * FROM employees WHERE department = 'IT';
Combine conditions:
SELECT * FROM employees WHERE salary > 50000 AND department = 'IT';
3. ORDER BY Clause
Syntax:
Examples:
Sort by salary:
4. LIMIT Clause
Examples:
5. Aggregation Functions
Summarize data.
Common Functions:
Examples:
Count employees:
Total salary:
SELECT SUM(salary) FROM employees;
Average salary:
6. GROUP BY Clause
Syntax:
Examples:
7. HAVING Clause
Examples:
Departments with more than 5 employees:
8. JOINs
INNER JOIN:
LEFT JOIN:
Fetch all rows from the left table and matching rows from the right.
RIGHT JOIN:
Fetch all rows from the right table and matching rows from the left.
Examples:
10. Aliases
Examples:
Rename a column:
Rename a table:
11. UNION
Syntax:
SELECT column1 FROM table1
UNION
SELECT column1 FROM table2;
Examples:
Examples:
```sql
SELECT * FROM employees WHERE name LIKE '%son';
Examples:
Not in HR department: