Subject | Join to same table twice - or joins vs subqueries |
---|---|
Author | |
Post date | 2015-08-20T18:30:24Z |
I'm trying to figure out what I did wrong. It seemed to work fine...but
now I'm seeing discrepancies.
Edit: I figured it out - I didn't have all the values in my table
"route_qualities". After tearing apart my query and doing numerous
tests - I finally actually looked at the data and saw what was missing.
Idiot.
But...now I want to ask a different question. The following select
works perfectly for me:
select r.id, a.node node, route_index, b.node link_node, c.quality_label
from routes r
join nodes a on r.node_id = a.id
join nodes b on r.link_id = b.id
join route_qualities c on r.quality = c.QUALITY
order by node, route_index;
Is there an alternate way of writing this with subqueries instead of
joins? If so, does that offer any advantages?
--
Daniel
now I'm seeing discrepancies.
Edit: I figured it out - I didn't have all the values in my table
"route_qualities". After tearing apart my query and doing numerous
tests - I finally actually looked at the data and saw what was missing.
Idiot.
But...now I want to ask a different question. The following select
works perfectly for me:
select r.id, a.node node, route_index, b.node link_node, c.quality_label
from routes r
join nodes a on r.node_id = a.id
join nodes b on r.link_id = b.id
join route_qualities c on r.quality = c.QUALITY
order by node, route_index;
Is there an alternate way of writing this with subqueries instead of
joins? If so, does that offer any advantages?
--
Daniel