I have an sql table with structure
CREATE TABLE IF NOT EXISTS `engine4_user_fields_values` (
`item_id` int(11) unsigned NOT NULL,
`field_id` int(11) unsigned NOT NULL,
`value` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`item_id`,`field_id`,`index`)
)
I want to select rows with field_id =’17’ AND value IN(5,8,7)+field_id =’20’ AND values IN(73,76)
I could not select it like given below, since if field_id is 17 it will not be 20!
SELECT * FROM `engine4_user_fields_values` WHERE (field_id ='17' AND value IN(5,8,7)) AND (field_id ='20' AND value IN(73,76))
If we use OR then it will select the value satisfying any of the condition.
Shall we use join for that? I am not sure about the code!
Any one please help me to get the select query for this
You could
group byitem, and use ahavingclause to require that the item has rows that match both conditions: