jeni
jeni

Reputation: 440

display from database

SELECT * FROM `tbl_wines` 
LEFT JOIN `tbl_wines_attrib` 
ON `tbl_wines`.`intWinesID` = `tbl_wines_attrib`.`intWinesID` 
AND `tbl_wines_attrib`.`intAttributeValueId` = 4 
WHERE `intStatus` = 1 
LIMIT 0 , 20 

I need to know if this query is correct. But am getting all the values from tbl_wines not only the value where intAttributeValueId = 4.

Can anyone help out?

Upvotes: 1

Views: 63

Answers (1)

Michael Berkowski
Michael Berkowski

Reputation: 270677

It looks like that condition has been placed as part of your JOIN rather than a WHERE condition. Instead try the following, moving tbl_wines_attrib.intAttributeValueId =4into the WHERE clause.

SELECT * FROM `tbl_wines` LEFT JOIN `tbl_wines_attrib` ON `tbl_wines`.`intWinesID` = `tbl_wines_attrib`.`intWinesID` WHERE `tbl_wines_attrib`.`intAttributeValueId` = 4 AND `intStatus` =1 LIMIT 0 , 20 

Upvotes: 2

Related Questions