Notizen
SQL- Relational Databases
Inhalt der Notizen (1)
Seite 1
SQL- Relational Databases
Joining the tables
• When
we use SQL to query related tables, we first need to list all tables that
we are using in the FROM section
• We
also have to include details of how the two tables are related. We do this in the WHERE section of the code
by specifying that the primary key in one table equals a foreign key in another
table
• E.g.
SELECT PetName, PetType
FROM tblPets , tblOwners
WHERE tblPets.OwnerID = tblOwners.OwnerID AND
tblOwners.Lname='Cratchett';
PetID
OwnerID
PetName
PetType
1
2
Fido
Dog
2
2
Fluffy
Cat
3
4
Gerald
Dog
4
3
Terence
Tarantula
OwnerID
FName
LName
1
Ronald
McDonald
2
Bob
Cratchett
3
John
Smith
4
Freddie
Mercury
Would give Results:
Fido Dog
Fluffy Cat
Informationen
- Beschreibung
- GCSE Computer Science (Databases) Notiz am SQL- Relational Databases, erstellt von Caitlin Bergan-Gander am 22/02/2016.
- Erstellt von
- Caitlin Bergan-Gander
- Aufrufe
- 2
- Bewertung