mysql - SQL 3-table join unrecognized column -


i'm trying join 3 tables in order generate list of our users , locations.

the first table lists of our users 2 separate ids--userid , uid. second table "orders" table user location data (delivery zone , billing zone) stored uid, , have third table acts location key (e.g., zone_id 18 = zone_name florida).

what want each userid, plus converted human-readable zone_name each user's billing zone and delivery zone.

my code works fine when try convert 1 of these zones. query works great:

select u.userid, o.delivery_postal_code, o.billing_postal_code, z1.zone_name webapp.users u left outer join practice_drupal.uc_orders o     on u.uid = o.uid     left outer join practice_drupal.uc_zones z1         on o.billing_zone = z1.zone_id; 

but error when try generate zone_name second zone (delivery). error "unknown column 'z2.zone_name' in 'field list' ". here's query:

select u.userid, o.delivery_postal_code, z1.zone_name, o.billing_postal_code,  z2.zone_name webapp.users u left outer join practice_drupal.uc_orders o     on u.uid = o.uid left outer join practice_drupal.uc_zones z1     on o.billing_zone = z1.zone_id; left outer join practice_drupal.uc_zones z2     on o.delivery_zone = z2.zone_id; 

i'm confused because scenario seems identical one, exception of using outer joins, can't bluefeet's solution work me: sql inner-join 3 tables?

any ideas? thanks!


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -