SQL SELECT

Most examples use this employees table:

idnamedeptsalarycity
1AshaIT65000Pune
2RaviHR42000Mumbai
3MeeraIT78000Pune
4KaranSales51000Delhi
5NehaHR47000Pune

Filtering with WHERE

SQL
SELECT name, city FROM employees
WHERE salary BETWEEN 45000 AND 70000
  AND city IN ('Pune', 'Delhi');
+-------+-------+ | name | city | +-------+-------+ | Asha | Pune | | Karan | Delhi | | Neha | Pune | +-------+-------+
OperatorExample
=, <>, >, <, >=, <=salary > 50000
BETWEEN … ANDsalary BETWEEN 40000 AND 60000
INdept IN ('IT', 'HR')
LIKEname LIKE 'M%' (% = any characters, _ = one character)
IS NULLemail IS NULL

ORDER BY, DISTINCT, LIMIT

SQL
SELECT name, salary FROM employees
ORDER BY salary DESC
LIMIT 3;
+-------+--------+ | name | salary | +-------+--------+ | Meera | 78000 | | Asha | 65000 | | Karan | 51000 | +-------+--------+
SQL
SELECT DISTINCT city FROM employees;
+--------+ | city | +--------+ | Pune | | Mumbai | | Delhi | +--------+
Track your progress through the SQL course