Choosing the columns you need
SELECT * is handy for a first look, but a report usually needs only a few columns. List them
after SELECT, separated by commas:
SELECT name, list_price
FROM productsThe columns come back in the order you list them, so you control the layout of the result. Column names must be spelt exactly as they are in the table: check the schema panel if you're not sure.
A query can run over several lines. Putting FROM on its own line is a common habit that makes
longer queries easier to read; the database doesn't mind either way.
Common mistakes
- A missing comma:
SELECT name list_pricedoesn't fail. It showsnameand renames itlist_price(you'll see why in the next lesson). Check your commas. - A comma after the last column:
SELECT name, list_price, FROM productsis a syntax error.