Pick the columns you need
Ask a table for just the columns you want with SELECT. About 7 minutes.
A table is rows and columns
Think of a college library's register. Every book gets one line, and every line has the same boxes: an id, the title, the author and the year it came out.
A database table is that register. Each line is a row, one book. Each box is a column, one fact about it.
Most questions you'll ask only need a few of those columns, not all of them.
SELECT picks the columns
To read a table you write a query. SELECT names the columns you want, and FROM names the table. The answer is a new, smaller table with just those columns, for every row.
The columns come back in the order you list them, so SELECT author, title puts the author first. A star, SELECT *, means every column: handy for a quick look, but real queries list what they need.
SELECT title, author FROM books;
| id | title | author | year |
|---|---|---|---|
| 1 | Godaan | Premchand | 1936 |
| 2 | Malgudi Days | R. K. Narayan | 1943 |
| 3 | Train to Pakistan | Khushwant Singh | 1956 |
FROM books: the query starts with every row of the books table.
A table students has columns id, name, branch and cgpa. What does SELECT name, cgpa FROM students return?
- AEvery student's name and cgpa
- BThe name and cgpa of the first student
- CEvery column of every student
Show the answer
Every student's name and cgpa. SELECT keeps every row and just the columns you list.
The scoreboard
The players table has one row per player. Show every player's name and runs, in that column order.
players(id, name, team, runs)
Up to 2,000 players