1

I have this result set

https://i.sstatic.net/7qb5g.jpg

and i'm trying to get entries as follow

get the ad_id of entries that have an attribute_id = 5 and value = 'Yamaha Mate V50' and attribute_id = 6 and value = 2012

i've tried stuff like

SELECT ad_id FROM value WHERE attribute_id = 5 && value = 'Yamaha Mate V50' && attribute_id = 6 && value = '2012'

this gives an empty result set

and if i did this

SELECT ad_id FROM value WHERE attribute_id = 5 && value = 'Yamaha Mate V50' || attribute_id = 6 && value = '2012'

i get ad_id = 1 and 3 which is good however i also get ad_id = 2 which is logical because it does have this condition (attribute_id = 6 && value = '2012')

so what should i do to select only the ad_ids that fulfill both conditions

(attribute_id = 5 && value = 'Yamaha Mate V50') "AND" (attribute_id = 6 && value = '2012')

Thanks in advance

1 Answer 1

2
SELECT ad_id FROM value
WHERE (attribute_id,value) IN ((5,'Yamaha Mate V50'),(6,'2012'))
GROUP BY ad_id
HAVING count(*)=2
Sign up to request clarification or add additional context in comments.

2 Comments

hellow @Michael Krelin - hacker your answer was good but i've faced another dead end the thing is i want not to extract entries between 2 values. it's kinda like this WHERE (attribute_id,value) IN ((5,'Yamaha Mate V50'),(6,'2012'), (7, between 200 and 600))
I'm not sure what you're talking about. If you want to add another pair of values, just make it 3 in count comparison.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.