Tables and SELECT
What a table is and how to read from one.
A real SQLite database runs inside your browser tab. Nothing to install.
A table holds rows
A database keeps data in tables. A table looks like a spreadsheet: each row is one record, and each column is one kind of value.
The practice database has one table called students. Each row is one student. The columns are id, name, city, marks and email.
To read a table you write a SELECT statement. The star means every column. Load the example and press Run.
SELECT * FROM students;Choosing columns
You rarely need every column. List the ones you want after SELECT, separated by commas.
The columns come back in the order you list them. Every statement ends with a semicolon.
SELECT name, city FROM students;Your turn: two columns
Write the query yourself, press Run to see the result, then press Check.
Practice task
Show only the name and the marks of every student.
Your answer is run and checked in the lesson. Try it now.
Naming a column in the result
AS gives a column a different heading in the result. It is useful when a report needs a clearer name.
The table itself does not change. Only the result of this one query uses the new heading.
SELECT name AS student_name, marks AS score FROM students;Your turn: a new heading
Use what you just saw.
Practice task
Show every student's name under the heading student_name.
Your answer is run and checked in the lesson. Try it now.