Jump to content

Multi-Level Database Queries across 5 tables...


WeddingLink

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.