I'm very noob when it comes to SQL and MySQL. I've discovered self-joining as a way to do comparisons of "x" where column A is the same e.g.
Tab1:
id colA x
-----------------
1 q1 0.1
1 q2 0.5
1 q3 0.7
2 q1 0.4
2 q2 0.9
2 q3 1.3
3 q1 0.2
3 q2 0.4
3 q3 0.1
QUERY:
select a.`colA`, a.`x`, b.`x`, c.`x`
from `tab1` as a
join `tab1` as b on a.`colA` = b.`colA`
join `tab1` as c on a.`colA` = c.`colA`
where a.`id` = 1 and b.`id` = 2 and c.`id` = 3
Gives me:
colA x x x
q1 0.1 0.4 0.2
q2 0.5 0.9 0.4
q3 0.7 1.3 0.1
Brilliant! I also just discovered that MySQL isn't capable of full outer joins, so using left, right or plain old join will give me the MINIMUM rows, i.e. if any colA values are missing for an id then they will be completely missing from the results, indeed if I take away q1 and q2 in any of the ids above I get one row.
q3 0.7 1.3 0.1
I've seen quite a few links on how to use UNION / UNION ALL to emulate a full outer join which I could frankenstein but these don't give me results as a nice comparison table. Is there not an easier way to tell the query during a SELF join to NOT ignore null values? I feel like this should be easy but have been scratching my head for hours and have googled so many answers I don't think I can see the wood because of all the trees.