sql - Maintaining the order by in union of two ordered by queries -



sql - Maintaining the order by in union of two ordered by queries -

i trying run below query looks doing wrong.

(just modified sample query clear understanding)

select name,total,rate business b rate > 100 order total desc union select name,total,rate business b rate <= 100 order rate asc

now want union of these 2 queries , in resultant output in first row output should come first query , output sec query in same sorted order single actual query giving.

let me know if still unclear. seek explain in more deep level.

it's simple: utilize union all instead of union.

select * ( select name,total,rate business b rate > 100 order total desc) x union select * ( select name,total,rate business b rate <= 100 order rate asc) y

union preserves order coded.

union removes duplicates , not guarantee order. databases sort output (to create duplicate detection easier).

sql oracle11g oracle-sqldeveloper

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -