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.