我想使用此查询显示有关 mysql 表的统计信息:
select * from t1 where product = ABC
Union
select * from t2 where product = ABC
以上查询在 t1 中生成 2 行产品为“ABC”的行,在 t2 中生成 3 行产品为“ABC”的行。该查询没有告诉我它来自哪个表。
如何更改查询以便我可以知道源表?
最佳答案
您可以在每个查询中包含一个唯一的标记,让您知道数据来自哪个表,如下所示:
select *, 't1' as tablename from t1 where product = 'ABC'
Union
select *, 't2' as tablename from t2 where product = 'ABC'
关于php - 从查询结果中获取mysql表名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48239245/