Filtering and sorting
WHERE, AND, IN, LIKE, ORDER BY and LIMIT.
SQL
SELECT name FROM students
WHERE dept = 'CSE' AND marks > 85;Output
Asha
SQL
SELECT name, dept FROM students
WHERE dept IN ('IT', 'ECE') AND name LIKE '%a%'
ORDER BY name;Output
Bala | IT
In LIKE, % means any number of characters. 'A%' finds names starting with A. Whether matching ignores capitals depends on the database.
Top scorers
SQL
SELECT name, marks FROM students
ORDER BY marks DESC
LIMIT 2;Output
Asha | 91 Esther | 88
LIMIT works in MySQL, PostgreSQL and SQLite. SQL Server uses TOP, and Oracle uses FETCH FIRST.