0

有什么方法可以在您的表名上使用“订单”功能。即我想联合两个表,然后按一列排序,然后按表名。

4

2 回答 2

9

将常量添加到描述您的表名的列列表中,例如

select *, 'TableA' as TableName
from TableA
union all
select *, 'TableB' as TableName
from TableB
order by TableName
于 2012-04-17T18:46:52.130 回答
0

您可以创建一个单独的列(假设您的列是col1and col2

select col1,col2,table_1 as table_name
from table_1
union
select col1,col2,table_2 as table_name
from table_2
order by col1,table_name;
于 2012-04-17T18:47:59.180 回答