All SQL topics
SQL TOPIC

SQL SELECT: choose the columns you need

SELECT is how every question starts: name the columns you want and the table they live in.

A query reads like a sentence: SELECT these columns FROM this table. List columns in the order you want them back, separated by commas.

Use AS to rename a column in the result, for example price AS list_price. SELECT * returns every column and is handy for a first look, but naming columns keeps reports readable and fast.

Worked example

Show each product with its category and price.

SELECT name, category, price
FROM products
LIMIT 5;
Result on the sample data
namecategoryprice
Wireless mouseAccessories29
Mechanical keyboardAccessories89
USB-C hubAccessories45
Noise-cancelling headphonesAudio249
Bluetooth speakerAudio79

Common mistakes

  • Forgetting the comma between column names, which silently turns the second name into an alias.
  • Using SELECT * in reports, so the output changes whenever the table gains a column.