Choosing columns
SELECT * returns every column. Usually you want only a few. Instead of *, list the columns you want, separated by commas:
SELECT name, score FROM student;
The result has just those columns, in the order you wrote them.

You can rename a column in the result with AS. This does not change the table — only the heading shown:
SELECT name AS pupil, score AS mark FROM student;
The headings become pupil and mark. This is handy for clear reports.
Question. The table student has the fields id, name, form and score. Write a query that shows each student's form, then their name.
Answer. Name the two fields in the order the question asks for:
SELECT form, name FROM student;
form | name
11A | Mei
11B | Jamal
11A | Sara
11B | Tom
11A | Lin
Writing SELECT name, form would show the same data with the columns the other way round, and the question asked for form first.
- A missing comma renames a column.
SELECT name score FROM studentis read asname AS score: you get one column headedscorethat holds the names. Put a comma between every two columns. - No comma after the last column.
SELECT name, score, FROM studentis a syntax error. ASchanges only the heading in the result. The table itself keeps its field names.
SELECT sélectionne des colonnes
Choosing columns keeps only the fields you name.
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
Select only the name et score columns from student, in that order.
Cliquez sur Exécuter pour voir le résultat ici.
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
Select name et score, but rename the headings to pupil et mark using AS.
Cliquez sur Exécuter pour voir le résultat ici.
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
Show each student's score premier, then their name. The starter lists the two columns the wrong way round: swap them.
Cliquez sur Exécuter pour voir le résultat ici.