Hi guys, i dont remember how to join a table to itself.. my table is:
| id | proc | value | kind |
| 1 | 1 | foo | a |
| 2 | 1 | bar | b |
| 3 | 2 | some | a |
And i need to retrieve the value col where proc is $proc and kind is both 'a' and 'b'.. well, i need to do have that (looking for proc = 1):
| v_a | v_b |
| foo | bar |
So i wrote this query:
SELECT
a.value AS v_a,
b.value AS v_b
FROM
(SELECT value FROM table WHERE proc = '1' AND kind = 'a') AS a,
(SELECT value FROM table WHERE proc = '1' AND kind = 'b') AS b
And works but only if in the table i have both rows for kind=a and kind=b.
But i need that if miss a row, i'll have a null value: if i look for proc=2 i must get:
| v_a | v_b |
| foo | NULL|
Instead, with my query i dont get anythong if the b or a row is missing.
Im working with mysql...How to do that?
Edit: I could use the UNION clause, but this wont allow me to have a NULL value when one row is missing (kind=a or kind=b)