Is it possible to provide the direction once for all columns in an order by statement?
i.e.
select *
from my_table
order by name desc, type desc
can you write the same thing using "desc" once?
Maybe something similar to this? (this doesn't work)
select *
from my_table
order by (name, type) desc
You could use row_number
for that:
select *
from my_table
order by
row_number() over (order by name, type) DESC
The final DESC will invert the row_number's order. So it'll flip ASC to DESC for both name and type.
No. The SQL standard doesn't allow that.
Having said that, there may be some RDBMS that do support a syntax like that. I'm just not aware of any.
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