Jump to content

Tricky Join Help!


thedepotnetwork

Recommended Posts

I am trying to do the following:

I have two tables, one contains all the vendors "vendors" the other contains the vendors service areas "vendors_service_areas"

 

I am attempting to only get the records from the "vendors_services_areas" table where the "vendor_state" in the "vendors" table is equal to 46 (utah). Both tables have the column, "vendor_id"

 

Here is what I had, but didn't work:

 

SELECT vca.vendor_id, vca.service_area, vca.service_type, vca.post_data

FROM vendors_service_areas AS vca, vendors AS v

WHERE v.vendor_state =46

AND v.vendor_id = vca.vendor_id

 

PLease Help! Still learning.

Link to comment
Share on other sites

It looks OK in general, although it could be rewritten as:

SELECT 
  vca.vendor_id, vca.service_area, vca.service_type, vca.post_data
FROM 
  vendors_service_areas AS vca 
CROSS JOIN 
  vendors AS v
USING(vendor_id)
WHERE 
  v.vendor_state =46 

 

But that's not really different.

 

What do you mean by 'it didn't work'. Did it throw any errors, or did it not return expected results?

 

 

Link to comment
Share on other sites

Yes, I tried but keep getting error:

 

SQL query: Documentation

SELECT *
FROM voting AS vt
CROSS JOIN vendors AS v
USING ( item_id, vendor_id )
WHERE v.vendor_state =46
LIMIT 0 , 30

MySQL said: Documentation
#1054 - Unknown column 'item_id' in 'from clause' 

 

item_id is on the table "voting" and it would be the matched "vendor_id" from vendors table where the state = 46

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.