Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
547 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
There are some situations where an inner join just won't help. Write a statement to return the FamilyID column from the Purchase table (using DISTINCT to return a unique column):
This shows that there are 5 different families referenced in the purchases table.
Now add this code in the left-hand side of the SQL Fiddle browser and rebuild your schema to include a new Family table in your model:
CREATE TABLE Family
([FamilyId] int, [FamilyName] varchar(9), [Cost] numeric)
;
INSERT INTO Family
([FamilyId], [FamilyName], [Cost])
VALUES
(1, 'Reptile', 2.99),
(2, 'Fish', 1.5),
(3, 'Bird', 3.49),
(4, 'Amphibian', 0.59),
(5, 'Mammal', 5),
(6, 'Insect', 4.28)
;
Note that there are 6 families. Amend your query above to link your purchase table to your family table (you will need to add f. or [family]. in front of the [FamilyID] column to make sure that you pick this up from the correct table in your SELECT command):
Interestingly the query still only returns 5 rows, even though above you clearly added 6 into the families table!
To return all the rows from the Family table we need to change the type of join. Depending on how you wrote the join try Right Outer or Left Outer Join.
Your query should now return all 6 rows!
Check the answer here.
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.