Jump to content

Need Help with a Cross Join Query


jimmyoneshot

Recommended Posts

I'm struggling to get a cross join query working in my script.

 

At the moment I have 2 tables in a mysql database - merchants and vouchers. The relationship is each merchant has many vouchers i.e. one to many.

 

The fields of the merchant table are:-

 

merchant_id (Primary Key), merchant name

 

and the fields in the vouchers table are:-

 

voucher_id (Primary Key), merchant_id (Foreign key from the merchants table to signify which merchant the voucher is related to), voucher_name

 

I'm trying to implement a feature which once the user clicks a certain letter all vouchers that belong to any merchants whose merchant_name begins with the clicked letter will be shown but I can't seem to get it to work with the following query and am unsure as to where I'm going wrong:-

 

SELECT m.merchant_name, v.* FROM merchants AS m CROSS JOIN vouchers AS v USING(merchant_id) WHERE m.merchant_name like '$letter%'

 

$letter is a vriable that stores the letter that was clicked by the user.

 

Can anyone suggest anything? Thanks for the help in advance 

Link to comment
https://forums.phpfreaks.com/topic/221223-need-help-with-a-cross-join-query/
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.