[英]How can I select the same number of records from two different tables in SQL Server
How can I select the same number of records from two different tables in SQL Server? 如何从SQL Server的两个不同表中选择相同数量的记录?
For example, I have a table A with 10 records and table B with 15 records; 例如,我有一个包含10条记录的表A和具有15条记录的表B; how can I select 10 records from A and 10 records from B ?
如何从A中选择10条记录,从B中选择10条记录?
If both the tables have same number and type of columns. 如果两个表的列数和类型相同。 Then use union or union all
然后使用并集或全部并集
Select col1,col2,col3 from table1
union
Select col1,col2,col3 from table2
Something like that? 这样的东西?
SELECT col1,col2,col3
FROM TABLE_A
UNION
SELECT TOP (SELECT COUNT(*) FROM TABLE_A) col1,col2,col3
FROM TABLE_B
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.