现在想显示Big表里面的记录,要求包含Small表的记录排前面,
请问用sql语句是否能实现?
比如:
Big记录
testId
1
2
3
4
5
6
7
8
9
..........Small记录
testId
5
6
7现在要显示成如下的排序:
Big记录
testId
5
6
7
1
2
3
4
8
9
..........
请问用sql语句是否能实现?
比如:
Big记录
testId
1
2
3
4
5
6
7
8
9
..........Small记录
testId
5
6
7现在要显示成如下的排序:
Big记录
testId
5
6
7
1
2
3
4
8
9
..........
解决方案 »
- 请问union的用法
- select themeId from t_theme
- SAMPLEDB.MDF' cannot be opened because it is version 655.
- 关于sql语句修改表中所有满足条件的语句
- 关于sql嵌套查询的问题
- 一个比较简单的触发器问题
- 这两种执行计划你认为哪种更好,为什么?
- 昨天遗留的一个问题,本人重新编写后还是没有解决,希望各位能帮忙看看,在线等待。。。。
- 请教关于SQL2005镜像配置问题
- 真的很着急!难道非得去问微软的人才行?
- SQL 里自己定义的函数能否调用自己?
- 如何控制不让其他人打开SQLSERVER 的企业管理器中某一个数据库?
union all
select testId from Big
select testId from Small
union
select testId from Big
union all
select testId from big where testid not in (select testid from small)
insert @b select 1
union all select 2
union all select 3
union all select 4
union all select 5
union all select 6
union all select 7
union all select 8
union all select 9declare @s table(id int)
insert @s select 5
union all select 6
union all select 7select b.* from @b b
left join @s s
on s.id=b.id
order by isnull(s.id,1000000),b.id
select *,frm='1' from @s s
union
select *,frm='2' from @b b where not exists(select 1 from @s s where s.id=b.id)
order by frm,id
那就不会有个数据在big里面没有的情况.select testId from Small
union all
select testId from Big where testid not in (select testid from small)或select testId from big where testid in (select testid from small)
union all
select testId from Big where testid not in (select testid from small)