DISTINCT in SQL
Level 374 keystrokes
DISTINCT removes duplicate values: the query lists each category of the products priced over 10 once, sorted by name (Electronics, Furniture, Tools).
SQL code
-- DISTINCT returns each category only once, even if many products share it1SELECT DISTINCT2 category-- Reads from the products table3FROM4 products-- WHERE runs before DISTINCT: only products priced over 10 are considered5WHERE6 price > 10-- Sorts the categories alphabetically: Electronics, Furniture, Tools7ORDER BY8 category;Output
+-------------+ | category | +-------------+ | Electronics | | Furniture | | Tools | +-------------+ 3 rows in set
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this SQL code and how often they appear.
;× 1>× 1