Data Filtering and Sorting
WHERE Clause
Section titled “WHERE Clause”SELECT * FROM employees WHERE salary > 50000;Comparison Operators
Section titled “Comparison Operators”-- EqualSELECT * FROM employees WHERE department = 'IT';
-- Not equalSELECT * FROM employees WHERE department <> 'HR';
-- RangeSELECT * FROM employees WHERE salary BETWEEN 40000 AND 80000;Logical Operators
Section titled “Logical Operators”-- ANDSELECT * FROM employeesWHERE department = 'IT' AND salary > 60000;
-- ORSELECT * FROM employeesWHERE department = 'IT' OR department = 'Finance';
-- INSELECT * FROM employeesWHERE department IN ('IT', 'HR', 'Finance');Pattern Matching
Section titled “Pattern Matching”-- LIKE with wildcardsSELECT * FROM employees WHERE first_name LIKE 'J%';SELECT * FROM employees WHERE email LIKE '%@gmail.com';NULL Values
Section titled “NULL Values”SELECT * FROM employees WHERE middle_name IS NULL;SELECT * FROM employees WHERE middle_name IS NOT NULL;ORDER BY
Section titled “ORDER BY”-- Ascending (default)SELECT * FROM employees ORDER BY last_name;
-- DescendingSELECT * FROM employees ORDER BY salary DESC;
-- Multiple columnsSELECT * FROM employees ORDER BY department, salary DESC;LIMIT/TOP
Section titled “LIMIT/TOP”-- MySQL/PostgreSQLSELECT * FROM employees ORDER BY salary DESC LIMIT 10;
-- SQL ServerSELECT TOP 10 * FROM employees ORDER BY salary DESC;