SQL: join within same table with different 'where' clause

Posted by Pmarcoen on Stack Overflow See other posts from Stack Overflow or by Pmarcoen
Published on 2010-05-19T15:40:51Z Indexed on 2010/05/19 16:00 UTC
Read the original article Hit count: 304

Filed under:
|
|

Ok, so the problem I'm facing is this, I have a table with 3 columns : ID, Key and Value.

ID | Key | Value
================
1  |  1  |  ab
1  |  2  |  cd
1  |  3  |  ef
2  |  1  |  gh
2  |  2  |  ij
2  |  3  |  kl

Now I want to select the value of Keys 1 & 3 for all IDs, the return should be like this

ID |  1  | 2
================
1  |  ab |  ef
2  |  gh |  kl

So per ID 1 row containing the Values for Keys 1 & 3.

I tried using 'join' but since I need to use multiple where clauses I can't figure out how to get this to work ..

© Stack Overflow or respective owner

Related posts about sql

Related posts about Oracle