Databases and SELECT
Databases and tables
A database stores information in tables. A table is a grid, a bit like a spreadsheet:
- each row is one record — for example, one student;
- each column is one field — for example, the student's name or score.
This course uses a small table called student. It has 5 records and 4 fields: id, name, form, and score.
データベースとテーブル
データベースは情報をテーブルに格納します。テーブルはグリッドで、スプレッドシートに似ています:
- 各行は一つのレコード — 例えば、一人の学生;
- 各列は一つのフィールド — 例えば、学生の氏名や得点。
このコースでは、studentという小さなテーブルを使用します。5つのレコードと4つのフィールドがあります:id, name, form, score。
Asking for data with SELECT
To read data from a table you write a query with SELECT.
The simplest query asks for every column of every row. The star * means "all columns":
SELECTchooses the columns —*means all of them.FROM studentsays which table to read.
The database replies with a result table (also called a result set): the rows your query asked for.
SELECTでデータを照会する
テーブルからデータを読むには、SELECTを含むクエリを書きます。
最も単純なクエリはすべての列のすべての行を要求します。星印*は「全列」を意味します:
SELECT * FROM student;
SELECTは列を選択 —*はすべてを指します。FROM studentはどのテーブルを読むかを指定します。
データベースは結果テーブル(結果セットとも呼ばれる)を返します — クエリで要求された行です。
A few rules
- Keywords like
SELECTandFROMare often written in capitals so they stand out. - End each statement with a semicolon
;. - An empty cell is shown as
NULL, which means "no value".
Now try it. Click Run to see the output, then Check answer.
いくつかのルール
SELECTやFROMのようなキーワードは、際立たせるために大文字で書かれることが多いです。- 各文の末尾にセミコロン
;を付けます。 - 空白セルは
NULLとして表示され、「値なし」を意味します。
これで試してみましょう。Runをクリックして出力を確認し、その後Check answerを押してください。
Common mistakes
- End a query with a semicolon:
SELECT ... FROM table;. SELECT *returns every column — name only the ones you need.
よくあるミス
- クエリの末尾にセミコロンを付ける:
SELECT ... FROM table;。 SELECT *はすべての列を返すため、必要なものだけを明記します。
SELECT … FROM … WHERE
WHERE keeps rows, then SELECT keeps columns — step through it. · WHEREは行を保持し、その後SELECTは列を保持 — 順を追って確認する。
Show the whole student table — every column and every row. Use SELECT * FROM ...;. · 全体のstudentテーブルを示す — 全列と全行。SELECT * FROM ...;を使用する。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。
Now keep only some columns and some rows. Show just the name and score of students in form 11A. Pick the two columns and add a WHERE form = '11A'. · Some columns and some rows. Just show the name and score of students in form 11A. Pick the two columns and add a WHERE form = '11A'.
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。