Select column value that matches a combination of other columns values on the same table

Posted by Ala on Stack Overflow See other posts from Stack Overflow or by Ala
Published on 2014-06-09T15:26:05Z Indexed on 2014/06/09 21:24 UTC
Read the original article Hit count: 282

Filed under:
|
|

I have a table called Ads and another Table called AdDetails to store the details of each Ad in a Property / Value style, Here is a simplified example with dummy code:

[AdDetailID], [AdID], [PropertyName], [PropertyValue]
 2            28      Color           Red
 3            28      Speed           100
 4            27      Color           Red
 5            28      Fuel            Petrol  
 6            27      Speed           70

How to select Ads that matches many combinations of PropertyName and PropertyValue, for example :

where PropertyName='Color' and PropertyValue='Red'
And
where PropertyName='Speed' and CAST(PropertyValue AS INT) > 60

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server