I want to join information from 4 tables. Its super complicated, and I'm not a guru with subqueries. Would appreciate some help, if anyone can understand this.
I have a product table, and I want to look up the dealer (in a dealer info table) and join the results. Then I need to join the results on the product.owner, to a table called accounts (on account.name). I think I worked it out as this:
> d as (SELECT device_id,dealer_id,owner_id from products) i as (LEFT
> JOIN dealer ON public.dealer.id = d.dealer_id) JOIN account ON
> i.owner_id = account.id;
Can someone help me structure this thing to report a complete result set with all information intact?
Edit:
SELECT pr.id, device_id, dealer_id, owner_id, pr.last_updated,model,brand FROM product pr
LEFT JOIN device dc ON pr.device_id = dc.id
LEFT JOIN dealer dlr ON dlr.id = pr.dealer_id
LEFT JOIN account accts ON accts.id = pr.owner_id