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

我可以检索上述sqlite 查询的输出,因为'none' 应该始终是第一项吗?即我想阻止两个结果集的组合排序。请帮助...

4

2 回答 2

6
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
于 2012-07-16T07:58:42.010 回答
3

我会避免SELECT *在联合查询中使用

SELECT 'none', '0', 0 AS sort
UNION
SELECT col1, col2, 1 AS sort
FROM category
WHERE id = '2'
ORDER BY sort ASC
于 2012-07-16T07:57:12.103 回答