Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

how to order a union sql

select *
from (
    select 1 as Rank, id, add_date from Table 
    union all
    select 2 as Rank, id, add_date from Table where distance < 5
    union all
    select 3 as Rank, id, add_date from Table where distance between 5 and 15
) a
order by rank, id, add_date desc
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #order #union #sql
ADD COMMENT
Topic
Name
7+3 =