简体   繁体   中英

Sqlite union and sort order

select 'none', '0'
union
select * from category where id='2'

Can I retrieve the output of above sqlite query as 'none' should always be the first item ?, ie I want to block from a combined sort of two resultsets. plz help...

select * from
(
select 'none' as col1, '0' as col2 union  select  * from category where id='2' 
) t
order by case when col1='none' then 0 else 1 end

I'd avoid using SELECT * in a union query

SELECT 'none', '0', 0 AS sort
UNION
SELECT col1, col2, 1 AS sort
FROM category
WHERE id = '2'
ORDER BY sort ASC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM