sql语句多条查询结果合并 SQL怎么把两个表的数据合在一起查询?

SQL怎么把两个表的数据合在一起查询?select top 10 * from(select * from 表1union allselect * from 表2) as Torder by 某字段u

SQL怎么把两个表的数据合在一起查询?

select top 10 * from(select * from 表1union allselect * from 表2) as Torder by 某字段

union all就是把俩表连接

然后把他俩连接的结果集起名叫T

然后你就可以用top了

你可以直接运行一下括号里那句,如果表结构相同你两个可以用*,如果部分字段相同,你就要把在一起的字段写到一起了,比如

select id,name from 表1union allselect id,name from 表2

类似这样