๐ป
SQL Editor
Ctrl+Enter also runs
๐
Exercises
๐
What is a JOIN?
A JOIN connects two tables using a column they share. Imagine the students table has student IDs, and the grades table also has student IDs. A JOIN matches them up so you can see which student got which grade.
๐ students
id | name
1 | Rhys
2 | Seren
1 | Rhys
2 | Seren
๐
๐ grades
student_id | grade
1 | A*
2 | B
1 | A*
2 | B
SELECT students.name, grades.grade
FROM students
INNER JOIN grades ON students.id = grades.student_id
FROM students
INNER JOIN grades ON students.id = grades.student_id
Result: Rhys โ A*, Seren โ B. The JOIN matched student ID 1 in both tables.
๐
Exam Tips
- SELECT always comes first โ it's what columns you want to see
- FROM tells the database which table to look in
- WHERE filters the results โ like a search filter
- Text values need single quotes: WHERE house =
'Red' - Numbers DON'T need quotes: WHERE score >
80 - * means "everything" โ SELECT * shows all columns
- Every query ends with a semicolon
;