DB Quacks SQL Tutorial · Chapter 4

When Harry Met Sally: A Table-JSON Love Story

The beaver gets excited and calls Professor Shellbert. We can connect duck visits from our database with pond locations from the JSON file! Join our pond_visits table with JSON location data!

Your task

Show duck names, pond names, visit dates, and water types by joining the 'data/pond_visits.csv' file with the 'data/pond_locations.json' file. You will be connecting data from two different file formats.

Hint

You need to join two different file sources - one CSV and one JSON - using their common field.

Expected result

A table showing duck names, pond names, visit dates, and water types.

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

data/pond_locations.json (3 rows)

columntype
pond_idBIGINT
pond_nameVARCHAR
locationSTRUCT(latitude DOUBLE, longitude DOUBLE, features VARCHAR[])
capacityBIGINT
amenitiesVARCHAR[]
water_typeVARCHAR
depth_metersDOUBLE
is_publicBOOLEAN
maintenance_scheduleVARCHAR

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

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

Start level 21 →

DuckDB docs for this lesson