DSA Factory
Free SQL queries lessonsSQL queries · Stage 0 · Reading a table · Step 1

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.

Row: one thing (a book). Column: one fact about it.

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 columns FROM table: every row, only those columns.
In code
SELECT title, author
FROM books;
SELECT title, author FROM books
books
idtitleauthoryear
1GodaanPremchand1936
2Malgudi DaysR. K. Narayan1943
3Train to PakistanKhushwant Singh1956

FROM books: the query starts with every row of the books table.

Move 1 of 4
Quick check

A table students has columns id, name, branch and cgpa. What does SELECT name, cgpa FROM students return?

  1. AEvery student's name and cgpa
  2. BThe name and cgpa of the first student
  3. CEvery column of every student
Show the answer

Every student's name and cgpa. SELECT keeps every row and just the columns you list.

Your problem

The scoreboard

The players table has one row per player. Show every player's name and runs, in that column order.

Tables
players(id, name, team, runs)

Up to 2,000 players

Write the query in your browserFree account, no card. Your query runs on real tables, with hints if you get stuck, and your progress is saved.
Sign up free to solve