Reputation: 4009
I currently have the following Query
SELECT * FROM tbl_Cars c
INNER JOIN tbl_Car_Parts cp ON c.Id = cp.Id
INNER JOIN tbl_Car_Factory cf ON cp.Id = cf.Id
However I have now realised that there are some Ids which are in the Cars Table which are then not in the Car Parts table so these are being omitted from my results while I want them included. I tried changing my INNER JOIN to a LEFT OUTER JOIN but it made no difference in the result set I am returned?
Upvotes: 3
Views: 92
Reputation: 4860
Use LEFT OUTER JOIN
in both of the joins.
SELECT * FROM tbl_Cars c
LEFT OUTER JOIN tbl_Car_Parts cp ON c.Id = cp.Id
LEFT OUTER JOIN tbl_Car_Factory cf ON cp.Id = cf.Id
Otherwise the second INNER JOIN
will invalidate your first LEFT OUTER JOIN
for those records that does not have ID (does not join) in the tbl_Car_Parts
table.
After a LEFT OUTER JOIN
you may be only use again INNER JOIN
if the table you are joining is not related with the previous ones that are joined using the LEFT OUTER JOIN
.
Upvotes: 3
Reputation: 1904
LEFT JOIN should have definitely solved your problem, Not sure why it didnt work. Just to be safe I used Left join on both the tables...
SELECT * FROM tbl_Cars c
LEFT JOIN tbl_Car_Parts cp ON c.Id = cp.Id
LEFT JOIN tbl_Car_Factory cf ON cp.Id = cf.Id
Upvotes: 0