WeddingLink Posted May 19, 2010 Share Posted May 19, 2010 Having trouble with this one. Latest MYSQL version... Trying to take from 5 related tables tables 1, 2, 3, 4 are related using vendor_id as shown in code tables 4, 5 are related through category_id... Where am I off in this? Also, how do I Limit say, table 3 to the first result, as there can be many, we only want the first on that table? SELECT v.vendor_id, v.vendor_firstname, v.vendor_lastname, v.vendor_title, v.vendor_address1, v.vendor_address2, v.vendor_city, st.state, v.vendor_zip, v.vendor_phone1, v.vendor_phone2, v.vendor_phone3, v.vendor_contact_phone1, v.vendor_contact_phone2, v.vendor_contact_phone3, v.vendor_fax1, v.vendor_fax2, v.vendor_fax3, v.vendor_email, v.vendor_contact_email, v.vendor_url, v.vendor_landing_page, v.vendor_description, v.vendor_datecreated, v.vendor_youtube_url, vsa.service_area FROM vendors as v LEFT OUTER JOIN states as st ON v.vendor_state = st.id LEFT OUTER JOIN vendors_service_areas as vsa ON v.vendor_id = vsa.vendor_id LEFT OUTER JOIN vendors_to_category as vtc ON v.vendor_id = vtc.vendor_id (SELECT DISTINCT vc.vcategory_name from vendors_category as vc where vtc.category_id = vc.vcategoty_id) LIMIT 100 Link to comment https://forums.phpfreaks.com/topic/202313-multi-level-database-queries-across-5-tables/ Share on other sites More sharing options...
andrewgauger Posted May 21, 2010 Share Posted May 21, 2010 Whats with the subquery? It looks out of place. Link to comment https://forums.phpfreaks.com/topic/202313-multi-level-database-queries-across-5-tables/#findComment-1061500 Share on other sites More sharing options...
WeddingLink Posted May 21, 2010 Author Share Posted May 21, 2010 Yes, it is out of place... Can't seem to figure out where to put it.... Link to comment https://forums.phpfreaks.com/topic/202313-multi-level-database-queries-across-5-tables/#findComment-1061601 Share on other sites More sharing options...
andrewgauger Posted May 21, 2010 Share Posted May 21, 2010 Is it a where condition? If so, put WHERE columnname IN between vendor_id and ( Link to comment https://forums.phpfreaks.com/topic/202313-multi-level-database-queries-across-5-tables/#findComment-1061694 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.