小编Pra*_*ase的帖子

从联合查询中获取表名?

这是我的查询

SELECT Id, productName, Largeimagepath, Discount, Price, Image FROM tablename1 where Active =1 
union 
SELECT Id, productName, Largeimagepath, Discount, Price, Image FROM tablename2 where Active =1
union  
SELECT Id, productName, Largeimagepath, Discount, Price, Image FROM tablename3 where Active =1
Run Code Online (Sandbox Code Playgroud)

它工作正常。

现在我想productName在将来获取各自的表名。

  1. 那么我怎样才能取到它呢?

我试过AS..像这样:

SELECT Id, productName, Largeimagepath, Discount, Price, Image
FROM tablename3 AS tablename
where Active = 1;
Run Code Online (Sandbox Code Playgroud)

但没有得到输出。

  1. 我应该如何更正查询并提高查询性能?

mysql performance union mysqli query-performance

10
推荐指数
1
解决办法
4万
查看次数

标签 统计

mysql ×1

mysqli ×1

performance ×1

query-performance ×1

union ×1