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
https://forums.phpfreaks.com/topic/186822-tricky-join-help/
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
https://forums.phpfreaks.com/topic/186822-tricky-join-help/#findComment-986586
Share on other sites

Hey! Yours worked! wow, thank you!

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 

 

Your SQL query has been executed successfully

Link to comment
https://forums.phpfreaks.com/topic/186822-tricky-join-help/#findComment-986590
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
https://forums.phpfreaks.com/topic/186822-tricky-join-help/#findComment-986596
Share on other sites

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.