union 关联查询排序问题
select top 3 a.name, a.id from aaa as a order by a.name asc
union
select top 3 b.name, b.id from bbb as b order by b.name asc
上面是报错的。
用临时对象表保存第一个搜索结果,也不好。总有意外情况,不是没删除表对象,就是已经删除了不能进行删除。
求的是查询的6条记录,每次都一样。当数据表不变的情况下。
[解决办法]
select * from (select top 3 a.name, a.id from aaa as a order by a.name asc)a
union
select * from (select top 3 b.name, b.id from bbb as b order by b.name asc)b