Sorry: the syntax is basically: query1 union query2 (so: both subqueries each need a FROM ... ) And: union is almost always an indication of bad design.
Well, the uses of UNION you have in your mind might be bad design. It's almost always incorrect to assume bad design when the use-case is not known. And the answer below works.
You are correct: I don't know the use-case But How could I know, you did not show it... BTW: a syntactically incorrect snippet in your question wont help you.
with sub as (some giant sql join) select max(id), somefield from sub group by somefield union all select min(id), someotherfield from sub group by someotherfield
(as an alternative to writing out the same inline view twice)
query1 union query2(so: both subqueries each need aFROM ...) And: union is almost always an indication of bad design.use-caseBut How could I know, you did not show it... BTW: a syntactically incorrect snippet in your question wont help you.Syntax wasn't the point of the snippet.I am going to make sticker with that text on it. Thank you!