Required to join 2 tables with their FKs in a 3rd table

The Tree table is the connection between the Forest table and the Species table. Think of it as two steps:

1) Starting from the Forest table, join to the Tree table (from Forest.Fo_name to Tree.Tr_forest)

2) Now that the Tree is known, join to the Species table (from Tree.species to Species.sp_name)

I’d write the final query like this:

SELECT Forest.Fo_name, Species.Sp_name, Species.Sp_woodtype
FROM Forest
JOIN Tree ON Forest.Fo_name=Tree.Tr_forest
JOIN Species ON Tree.species=Species.sp_name
WHERE Fo_loc="ARTIC"
ORDER BY Fo_name, Sp_name

Leave a Comment