I want to ORDER BY
the result of a MINUS
query.
My first attempt doesn't work:
SELECT *
FROM Table1
MINUS
SELECT *
FROM table2
WHERE table2.foo = 'bar'
ORDER BY foo
How would you do it?
oops: I was doing ORDER BY table2.foo
instead of just ORDER BY foo
. Now it works.
However, to answer your question, you can use a with query:
with tmp_minus as (
SELECT *
FROM Table1
MINUS
SELECT *
FROM table2
WHERE table2.foo = 'bar'
)
select * from tmp_minus
ORDER BY foo
You should also be able to do a subselect:
select * from (
SELECT *
FROM Table1
MINUS
SELECT *
FROM table2
WHERE table2.foo = 'bar'
) tmp_minus
ORDER BY foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With