Σχετικά με το Μάθημα
SQL Joins
- SQL Joins are used to combine rows between two tables in a relational database based on a common column – which column can be the concatenation of several ones (hint: search for composite keys).
- Joins are so important because with just one query, we can obtain a single row full of information! Just find the common key-field between tables (mostly a primary key of one table is combined with the foreign key of the other table – but this is not a rule).
Joins Explained
Each row of the owners table identifies a different pet owner, where the ID column is a unique identifier. The Pet_ID column (in the owners table) contains the ID for the pet that belongs to the owner (this number matches the ID for the pet from the pets table).
Example:
- The pets table shows that Dr. Harris Bonkers is the pet with ID 1.
- The owners table shows that Aubrey Little is the owner of the pet with ID 1.
Putting these two facts together, Dr. Harris Bonkers is owned by Aubrey Little. Likewise, since Veronica Dunn does not have a corresponding Pet_ID, she does not have a pet. And, since 5 does not appear in the Pet_ID column, Maisie does not have an owner.