I have the following data:
materials
==========================
id | quantity |type
---------+----------+-----
1 |111 |1
2 |240 |2
3 |412 |2
4 |523 |1
For the sake of the simplicity of the example, let's say I need to select materials into pairs by types, so the desirable result would look like that:
id | quantity |type |id | quantity |type
---------+----------+-----+---------+----------+-----
1 |111 |1 |2 |240 |2
4 |412 |1 |3 |412 |2
Data will match perfectly, so there would be no empty entries in pairs.
So far I can think only of union
, like that:
select * from materials where type = 1
union all
select * from materials where type = 2
But obviously, that's not what I'm looking for. Is that even possible?
P.S. Please, do not simplify the answer to ...where type in (1,2)
, because actual condition is not mergeable like that.