I have 6 tables that I'm trying to connect together in 1 query; however, I can't quite figure out how to write the query.
Here are my tables in bold and the columns that they contain.
pg
pgid
ipg
ipgid
roid
pgid
ug
ugid
iug
iuid
roid
ugid
ro
roid
inid
in
inid
My goal is to output the inid field given certain criteria from the pg and ug tables. I want to find all the inid entries where pg.pgid=1 and ug.ugid=2. This involves a a lot of joins and I think some select in statments but I'm not familiar enough with how to piece that all together.
Here is what I have so far...
SELECT inid
FROM in
INNER JOIN ro ON in.inid = ro.inid
INNER JOIN iug ON ro.roid = iug.roid
INNER JOIN ug ON iug.ugid = ug.ugid
INNER JOIN ipg ON ro.roid = ipg.roid
INNER JOIN pg ON ipg.pgid = pg.pgid
WHERE pg.pgid = 1
AND ug.ugid = 2
pgmight unnecesary; it will only filter results if there is nopgid=1.