So I'm just starting to learn SQL, and hit upon the following problem. Suppose I have a table with 3 columns like so:
ID | Property_Name | Property_Value 1 | Color | "Blue" 1 | Size | "Large" 2 | Color | "Red" 3 | Color | "Orange" 3 | Size | "Small" 4 | Color | "Blue" 4 | Size | "Large" ...
Now, suppose I want to find the IDs that have Color=Blue and Size=Large (aka. ID 1 and 4), how would I best do this. The best way I came up with is the following, but it seems clunky...
SELECT ID FROM PropertyTable
WHERE
ID IN (
SELECT ID FROM PropertyTable WHERE
Property_Name='Color' AND Property_Value='blue' )
AND
(Property_Name='Size' AND Property_Value='Large')
Thank you :)
EDIT: Forgot to add preformat tags to the example table text. Just did so.