DB Quacks SQL Tutorial · Chapter 4

No Duck LEFT Behind

Social worker duck approaches with concern. Some shy ducks never visited ponds! Our previous reports only showed swimming ducks. I want ALL ducks included, even homebodies who stayed home!

Your task

Show all ducks and their pond visits, including ducks who never visited any pond, by joining the ducks table with 'data/pond_visits.csv'. You will be ensuring no ducks are excluded from the results.

Hint

You need a join that keeps all records from one table, even if there are no matches in the other table.

Expected result

A table showing all ducks and their pond visits (NULL for ducks who never visited).

Tables

duck_diaries (10 rows)

columntype
diary_idBIGINT
duck_idBIGINT
entry_dateDATE
diary_textVARCHAR
moodVARCHAR

duck_surveys (5000 rows)

columntype
survey_idBIGINT
duck_idBIGINT
ageBIGINT
favorite_foodVARCHAR
favorite_pondBIGINT
swimming_ratingBIGINT
migration_preferenceVARCHAR
social_behaviorVARCHAR
health_statusVARCHAR
activity_levelVARCHAR
survey_dateDATE
survey_locationBIGINT

ducks (15 rows)

columntype
idBIGINT
nameVARCHAR
ageBIGINT
speciesVARCHAR
birth_dateDATE
arrival_dateDATE

ponds (3 rows)

columntype
pond_idBIGINT
pond_nameVARCHAR
location_latDOUBLE
location_lngDOUBLE
capacityBIGINT
featuresVARCHAR[]
amenitiesVARCHAR[]

Files

data/pond_visits.csv (40 rows)

columntype
visit_idBIGINT
duck_idBIGINT
pond_idBIGINT
visit_dateDATE
duration_minutesBIGINT

Database: https://dbquacks.com/data/databases/tutorial.duckdb

This page as markdown: https://dbquacks.com/tutorial/20.md

Start level 20 →

DuckDB docs for this lesson