B4Coder
0%
LessonAbout 5 min

Chapter 1 · Lesson 1 of 5

01. Tables and your first query

What a database is: tables of rows and columns. Then SELECT * FROM to show a whole table.

A database keeps information in tables, like a register or a spreadsheet. Each row is one thing (one student), and each column is one fact about it (their name, their class, their city).

Apps everywhere keep their data like this: your school's attendance, a shop's orders, a bank's accounts. SQL is the language for asking a database questions. You'll write it here in SQLite, the database inside every phone.

Here's a question in SQL: "show everything in the students table". SELECT * means every column, and FROM students says which table.

SQL
SELECT * FROM students;

Result

id | name    | class | section | city       | age
---+---------+-------+---------+------------+----
1  | Asha    | 10    | A       | Chennai    | 15
2  | Ravi    | 10    | B       | Madurai    | 16
3  | Meera   | 9     | A       | Coimbatore | 14
4  | Arjun   | 10    | A       | Chennai    | 15
5  | Divya   | 9     | B       | Salem      | 14
6  | Karthik | 11    | A       | Madurai    | 16
7  | Priya   | 11    | B       | NULL       | 17
8  | Rahul   | 9     | A       | Chennai    | 14
9  | Sneha   | 10    | B       | Coimbatore | 15
10 | Vikram  | 11    | A       | Trichy     | 16

A question like this is called a query, and what comes back is its result: a table of its own. The ; at the end marks where a statement finishes.

Your turn

1Steps

  1. 1The school's database also has a subjects table. Show everything in it: every column and every row.

Write it in query.sql. The tables are in the Tables tab, beside Results.

Use: SELECT, FROM

2Expected output

Your query should show

idnameteacherperiods
1MathsMs. Rani6
2ScienceMr. Kumar6
3EnglishMs. Fernandes5
4TamilMr. Selvam4
5Social ScienceMs. Banu4

5 rows, in any order. The column names count too.

3Hints

Stuck? Open one hint at a time: each gives a bit more help.

Hint 1

It's one line, made the same way as the query for students, with a different table.

Hint 2

SELECT * means every column. After FROM, put the name of the table.

Hint 3

The table is called subjects, so the query ends with FROM subjects;

query.sql