SELECT reads data out of a table. You name the columns you want and the table they live in, and the database hands back a result set: a temporary table holding just those columns, one row for every row in the source.
The example table
Section titled “The example table”The examples use the Productions table from the example database, an invented list of film and TV productions:
| ProductionID | Title | Format | Country | Budget |
|---|---|---|---|---|
| 1 | The Lantern Keepers | Drama series | UK | 18,500,000 |
| 2 | Quarry Lane | Feature film | UK | 7,200,000 |
| 3 | Saltmarsh | Feature film | Ireland | 3,900,000 |
| 4 | Six Bells | Drama series | UK | 11,000,000 |
| 5 | Fennick’s Return | Documentary | Canada | 850,000 |
Choosing columns
Section titled “Choosing columns”List the columns after SELECT, separated by commas, and the table after FROM:
SELECT column1, column2FROM table_name;To see each production’s title and where it is made:
SELECT Title, CountryFROM Productions;| Title | Country |
|---|---|
| The Lantern Keepers | UK |
| Quarry Lane | UK |
| Saltmarsh | Ireland |
| Six Bells | UK |
| Fennick’s Return | Canada |
The columns come back in the order you list them, whatever their order in the table.
Every column
Section titled “Every column”An asterisk stands for every column in the table:
SELECT * FROM Productions;This returns the whole table above.