Browse 553 attributed reviews, viewable separately for our classroom and online training
Practise SQL in your browser with SQL Fiddle
Part thirteen of a sixteen-part series of blogs

Some of our poor delegates don't have the luxury of a home computer to install SQL on (even worse some have made bad life choices and picked a Mac). The good news is that you can still practise your SQL skills in your web browser, using the impressive SQL Fiddle site. Have no fear, SQL Fiddle is here, a browser based sandbox to bring you cheer!

  1. Installing and configuring SQL Fiddle
  2. SQL Fiddle Exercise 1 - SELECT
  3. SQL Fiddle Exercise 2 - Order By
  4. SQL Fiddle Exercise 3 - Numeric Filters
  5. SQL Fiddle Exercise 4 - Date Filter
  6. SQL Fiddle Exercise 5 - Text Filters
  7. SQL Fiddle Exercise 6 - Cast or Convert Functions
  8. SQL Fiddle Exercise 7 - Conditional Function
  9. SQL Fiddle Exercise 8 - Counting Words
  10. SQL Fiddle Exercise 9 - Formatted Dates
  11. SQL Fiddle Exercise 10 - Date Calculations
  12. SQL Fiddle Exercise 11 - Inner Join
  13. SQL Fiddle Exercise 12 - Outer Join (this blog)
  14. SQL Fiddle Exercise 13 - Grouping Data
  15. SQL Fiddle Exercise 14 - Having
  16. SQL Fiddle Exercise 15 - All together now!

Posted by Sam Lowrie on 01 July 2021

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

SQL Fiddle Exercise 12 - Outer Join

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):

SQL Fiddle

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):

SQL Fiddle

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.

SQL Fiddle

Your query should now return all 6 rows!

Check the answer here.

This blog has 0 threads Add post