OK, so I’ve found questions that cover how to do this with only two tables, tons of questions that explain how to do this if the ID does NOT exist in other tables, but not a solution to this query.
Basically, I have one table of wine vintages.
I then have four other tables that contain different types of content that is tied to a specific vintage (i.e. videos, blogs etc.)
I basically need to be able to pull a list of vintages that are in use i.e. where the vintage ID is used in one or more of the four content tables.
The closest I can get is this:
SELECT DISTINCT vintage_id FROM `pr_video_vintage`
INNER JOIN pr_video ON pr_video.fk_vintage_id = pr_video_vintage.vintage_id
INNER JOIN pr_reports ON pr_reports.fk_vintage_id = pr_video_vintage.vintage_id
INNER JOIN pr_reports_notes ON pr_reports_notes.fk_vintage_id = pr_video_vintage.vintage_id
INNER JOIN pr_blog_entries ON pr_blog_entries.fk_vintage_id = pr_video_vintage.vintage_id
ORDER BY `pr_video_vintage`.`vintage_id` ASC
But this (understandably I guess) only returns IDs that exist in ALL of the tables.
What I need is some form of ‘OR’ JOIN, but can’t find any information out about how to go about doing this.
tips? 🙂
Try this:
or
or