mysql - Using results from a query within the same query -


i have rather big sql statement working in ms access 2010. here goes:

select  w.id wid, w.wpt_ty ty, w.wpt_num num, w.wpt_nxt nxt, w.latdeg lat, w.londeg lon, w.alt alt, w.mission_id mid, w.ctg1 ctg1, w.ctg2 ctg2, w.ctg3 ctg3, w.ctg4 ctg4, w.wpt_index indx, w.vel vel, w.tu tu, r.route_num rnum, r.ac_num ac, r.route_type rtype, r.lastupdatedon d8, r.lastupdatedby auth, r.flight_wpt_count wfcount, m.mission_name msnname, v.description vstatus, r.disallowed_reason_id did, cw.wpt_num c1num, cr.matching_route_id c1mrid, cw.wpt_index c1indx, cru.runway_name c1rnwy, cr.route_num c1rnum validation v  (right join runways cru   inner join (routes cr   inner join waypoints cw on cr.id = cw.route_id)   on runways.id = routes.runway_id inner join ((missions m  inner join routes r on m.id = r.mission_id)  inner join waypoints w on (r.id = w.route_id)  , (m.id = w.mission_id)) on  v.id = r.validated  (((r.matching_route_id)=307543) , ((r.validated) <> 0 )) , (((cw.mission_id)=mid) , ((cw.wpt_num) = (ctg1)))) 

if @ bottom, can see referencing values ctg1 , mid on right join while inner joins reference other literal values. want same ctg2, ctg3, , ctg4

right running these 2 separate queries finding way slow. if can join combine queries (sort of how showing here) speed things greatly. @ loss how to:

  • using select values earlier in said query inner/left join , push them values needed on right join.
  • i may using joins incorrectly, thought had combining data possible same tables, on different pivot points.
  • how use ms access gui write query this.
  • i know ms access tagging mysql in case there similar queries there can ported ms access?

have tried using union this?

it allow execute query (as 2 queries, mentioned possibility), , join results output.

be warned, eat (only show 1 of) duplicates in results set.

i suggest reading on different types of joins own benefit, in following answer:

mysql joins


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -