SELECT, WHERE and ORDER BY
Every query starts here: which columns, from which table, which rows, and in what order. The tables hold a small company's staff.
● A real database, running in your browser. Nothing you type leaves this page.
Exercise 1 of 6
Everything in a table
SELECT says what you want, and FROM says where it is. * means all columns. It's fine for a quick look, while real applications should name their columns.
Your task
Show every column of every row in departments.
Tables and columns
or Ctrl+Enter
What you'll practice
- Everything in a table.
SELECTsays what you want, andFROMsays where it is.*means all columns. It's fine for a quick look, while real applications should name their columns. - Only some columns. Name the columns you want, separated by commas.
- Only some rows.
WHEREkeeps the rows where a condition is true. - Text goes in quotes. Text values go in single quotes. In PostgreSQL, double quotes mean a column name, and that's a classic error. Text values go in single quotes. SQLite may accept double quotes as text too, but that's a leniency you shouldn't rely on, as other databases treat them as column names.
- Sort and limit. Without
ORDER BY, the order isn't guaranteed, whatever it looks like.DESCmeans largest first, andLIMITkeeps the first few rows. - No duplicates.
DISTINCTremoves repeated rows from the result.