当前位置: 代码迷 >> Sql Server >> select 的排序有关问题 高手们快来啊多谢了·······················
  详细解决方案

select 的排序有关问题 高手们快来啊多谢了·······················

热度:24   发布时间:2016-04-27 15:18:07.0
select 的排序问题 高手们快来啊,谢谢了·······················
有一条sql
select * from table 
where id in (select id from table1) 
or id in (select id from table2)

就是id 要在两个表里选,我怎么样要让table1的id 排在 table2的前面

希望高手回答,谢谢了 !!!

------解决方案--------------------
用 union 呢
------解决方案--------------------
SQL code
select * from (select *, NewOrder=1 from tb where id in (select id from table1) union all select *, NewOrder=2 from tb where id in (select id from table2) and id not in (select id from table1)) Torder by NewOrder
  相关解决方案