DB Quacks SQL Tutorial · Chapter 4

Pond Bouncers: The WHERE-JOIN Chronicles

Security guard goose swims over with a badge. We have VIP ponds for older ducks only! Show me visits where ducks older than 3 years went to ponds. I need to verify our access rules work correctly.

Your task

Show visits where ducks older than 3 years visited ponds, combining the ducks table with 'data/pond_visits.csv' and filtering by age. You will be joining and filtering data simultaneously.

Hint

First join the tables, then add a condition to filter for specific age criteria.

Expected result

A table showing visits by ducks older than 3 years.

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/18.md

Start level 18 →

DuckDB docs for this lesson