Relative Content

Tag Archive for sqlpostgresqljoin

Trying to get all related records when at least one matches

I have a photos table, a tags table, and a bridge table called photos_tags. Imagine there’s a photo which has been tagged with dog, cat, and bird. This means that there’ll be 1 record in photos, 1 record in tags, and 3 records in photos_tags.

Trying to get all related records when at least one matches

I have a photos table, a tags table, and a bridge table called photos_tags. Imagine there’s a photo which has been tagged with dog, cat, and bird. This means that there’ll be 1 record in photos, 1 record in tags, and 3 records in photos_tags.

Postgres joins showing duplicate rows

base data table contains (parent_id, parent_name,location)== 1 record child data table contains (s_id, child_name,parent_id)==2 records school data table contains (school_id, school_name,parent_id)== 2 records When I write a postgresql select statement, I get 4 records SELECT a.parent_id, a.parent_name,a.location, b.c_id,b.child_name, c.school_id,c.school_name FROM base a LEFT JOIN child b ON a.parent_id=b.parent_id LEFT JOIN school c ON a.parent_id=c.parent_id My […]