我想使用此查询显示有关mysql表的统计信息:
select * from t1 where product = ABC
Union
select * from t2 where product = ABC
上述查询在t1中产生2行,其中product =“ABC”,在t2中产生3行,product =“ABC”。查询没有告诉我它来自哪个表。
如何更改查询以便我知道源表?
答案 0 :(得分:1)
您可以在每个查询中包含一个唯一标记,以便让您知道数据来自哪个表:
select *, 't1' as tablename from t1 where product = 'ABC'
Union
select *, 't2' as tablename from t2 where product = 'ABC'