Ch 2 · Sorting & Filtering · SQL

Topic 2 of 8 in SQL — Query a Real Database — 2 lessons.

ORDER BY & LIMIT

ORDER BY sorts results (DESC = highest first). LIMIT caps how many rows — great for "top N". In the example, employees are sorted from highest to lowest salary and only the first three rows come back, so you get the three best-paid people. Try removing DESC to see the order flip, or change the number after LIMIT.

LIKE & IN

LIKE matches text patterns (% = any characters). IN matches a list of values. The example finds every employee whose first name starts with the letter A, because 'A%' means an A followed by anything. IN saves you writing long chains of OR conditions. Try the tip query to pull out employees from departments 1 and 3 in one go.

All topics in SQL Beginner

  1. Reading Data
  2. Sorting & Filtering
  3. Combining & Summarising
  4. SQL Basics: SELECT Queries
  5. SQL CREATE TABLE and Data Types
  6. SQL Data Import and Export
  7. SQL INSERT, UPDATE, DELETE
  8. SQL String Functions