SQL ยท Chapter 3 of 42
SQL SELECT
SELECT reads rows from one or more tables. Choose specific columns to fetch, or use `*` for all columns.
Structure: `SELECT columns FROM table;`
Syntax
SELECT column1, column2 FROM table_name;Selecting columns
List column names separated by commas. `SELECT *` grabs all โ great for exploring, but avoid in production.
Computed columns
You can compute values on the fly: `SELECT price * 1.18 AS price_with_tax FROM products;`
Example 1 (sql)
SELECT name, email FROM users;Output
name | email
Ana | ana@x.com
Ben | ben@x.comFetch only the columns you need.
Example 2 (sql)
SELECT name, price * 1.18 AS gross FROM products;Output
name | gross
Book | 118.00
Pen | 23.60Alias a computed column with AS.
Key points
- SELECT reads data.
- List columns explicitly (avoid `*` in production).
- AS renames a column in the output.
- Computed expressions are allowed.
๐ก Note: `SELECT *` returns whatever columns exist today โ if the schema changes, your queries silently return different results.
