order by 的问题

来源:百度知道 编辑:UC知道 时间:2024/07/13 20:03:32
数据库里ID列有:
1
2
3
4
5
6
我想让程序取读的时候接:
4
1
2
3
5
6
来排序,SQL语句有办法实现吗?

select ID from tablename where ID=4
UNION
select ID from tablename where ID!=4 order by ID

如果您是要挑出ID=4的排到前面,其它按ID小到大排列,就这样:
select * from tablename order by case when id=4 then 0 else id end

不知道。。
我知道有从小到大和从大到小的顺序。。。