SQL SELECT
Most examples use this employees table:
| id | name | dept | salary | city |
|---|---|---|---|---|
| 1 | Asha | IT | 65000 | Pune |
| 2 | Ravi | HR | 42000 | Mumbai |
| 3 | Meera | IT | 78000 | Pune |
| 4 | Karan | Sales | 51000 | Delhi |
| 5 | Neha | HR | 47000 | Pune |
Filtering with WHERE
SELECT name, city FROM employees
WHERE salary BETWEEN 45000 AND 70000
AND city IN ('Pune', 'Delhi');
+-------+-------+
| name | city |
+-------+-------+
| Asha | Pune |
| Karan | Delhi |
| Neha | Pune |
+-------+-------+
| Operator | Example |
|---|---|
| =, <>, >, <, >=, <= | salary > 50000 |
| BETWEEN … AND | salary BETWEEN 40000 AND 60000 |
| IN | dept IN ('IT', 'HR') |
| LIKE | name LIKE 'M%' (% = any characters, _ = one character) |
| IS NULL | email IS NULL |
ORDER BY, DISTINCT, LIMIT
SELECT name, salary FROM employees
ORDER BY salary DESC
LIMIT 3;
+-------+--------+
| name | salary |
+-------+--------+
| Meera | 78000 |
| Asha | 65000 |
| Karan | 51000 |
+-------+--------+
SELECT DISTINCT city FROM employees;
+--------+
| city |
+--------+
| Pune |
| Mumbai |
| Delhi |
+--------+
Track your progress through the SQL course