Jump to content

Trouble using Joins with where statement


stig1

Recommended Posts

"select tbl_prod.prodID, tbl_prod.itmClass, tbl_prod.prodName, tbl_prod.prodDesc, tbl_prod.prodImg from tbl_prod, tbl_prod_items where tbl_prod.prodName like '%".$qsearch."%' or tbl_prod.prodDesc like '%".$qsearch."%' or tbl_prod_items.itmDesc like '%".$qsearch."%' and tbl_prod.prodHide is null order by tbl_prod.prodName asc"

 

$qsearch = the search term a customer enters in.

 

The join I require is to find the search term in either table but no duplicate results.

 

I have to fields that should join, however they are varchar(20) fields.

 

tbl_prod.itmClass and tbl_prod_items.itmClass is a 1 to many relationship.

 

If i put the value 80mm in the search box, I should be able to retrieve all the values related to 80mm.

 

How do I go about making this join with the where statement? Cause it doesnt seem to be working for me!

Well, you're also missing parens for your OR conditions!

 


select 
tbl_prod.prodID, tbl_prod.itmClass, tbl_prod.prodName, tbl_prod.prodDesc, tbl_prod.prodImg 
from tbl_prod
tbl_prod_items using( itemClass )
where ( tbl_prod.prodName like '%".$qsearch."%' 
or tbl_prod.prodDesc like '%".$qsearch."%' 
or tbl_prod_items.itmDesc like '%".$qsearch."%' )
and tbl_prod.prodHide is null 
order by tbl_prod.prodName asc

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.