If I have two tables in a MySQL database that both have a column called order_number
, given an order_number
value but not knowing which table it comes from how would I go about setting up a query that would return the name of the table it was found in?
如果我在MySQL数据库中有两个表都有一个名为order_number的列,给定一个order_number值但不知道它来自哪个表我将如何设置一个查询,该查询将返回它在表中找到的表的名称?
I am particularly interested in the name of the table so I can set up subsequent updates to that table.
我对表的名称特别感兴趣,所以我可以设置该表的后续更新。
Also, I am using PHP for the handling of the query.
另外,我使用PHP来处理查询。
1 个解决方案
#1
2
select "tableA" as tableName,order_number from tableA where order_number=5
UNION
select "tableB" as tableName,order_number from tableB where order_number=5;
#1
2
select "tableA" as tableName,order_number from tableA where order_number=5
UNION
select "tableB" as tableName,order_number from tableB where order_number=5;