SELECT * returns every column. Most of the time you need only some of them.
List the columns
Write the column names after SELECT, with a comma between each two:
sql
SELECT name, country FROM customers;SELECT name, countryreturn these columnsFROM customersfrom this table;end
customers
| id | name | country | city | |
|---|---|---|---|---|
| 1 | Ava Chen | ava.chen@example.com | CA | Toronto |
| 2 | Liam Patel | liam.p@example.com | CA | Peterborough |
| 3 | Sofia Rossi | sofia.rossi@example.com | IT | Milan |
The result has the columns in the order you list them. SELECT country, name puts country first.
* means "every column, in the table's order".
Write it your way
SELECTandFROMare keywords. Upper case or lower case both work. This course writes keywords in upper case so they stand out.- Spaces and new lines between words do not matter. A long query can use one line per part:
sql
SELECT name,
email
FROM customers;- The
;marks the end of a statement. You need it between two queries in the same run. With one query, it is optional.