SQL SELECT
Choose which columns (or calculations) a query returns.
Syntax
SELECT column1, column2, expression AS alias FROM table;
Every query that reads data starts with SELECT. * means every column. Each item can be a column, a calculation or a function, renamed with AS.
Example
Query (on the shop database used in the SQL course)
SELECT name, price, price * 1.1 AS price_with_gst FROM products LIMIT 5;
Result
| name | price | price_with_gst |
|---|---|---|
| Wireless mouse | 29.0 | 31.9 |
| Mechanical keyboard | 119.0 | 130.9 |
| USB-C hub | 49.0 | 53.9 |
| 27-inch monitor | 329.0 | 361.9 |
| Noise-cancelling headphones | 249.0 | 273.9 |
5 rows
Good to know. List the columns you need rather than
* in real queries.Related
Learn it step by step in the free lesson SELECT: Choosing Columns, with exercises that check your queries.