gpt4 book ai didi

mysql - 如何使用选择查询查找表名

转载 作者:行者123 更新时间:2023-11-30 00:23:43 25 4
gpt4 key购买 nike

SELECT product FROM Table_name_1 
WHERE id = '% textbox1.text %'
UNION
SELECT product FROM Table_name_2
WHERE id = '% textbox1.text %'
UNION
SELECT product FROM Table_name_3
WHERE id = '% textbox1.text %'

通过这个代码,我能够获取产品。但我怎么知道这个结果是从哪个表中取出的呢?所以我也想知道表名。

最佳答案

您还可以选择常量值并为其指定列名称。

SELECT product, 'Table_name_1' as table FROM Table_name_1 WHERE id = '% textbox1.text %'
UNION
SELECT product, 'Table_name_2' as table FROM Table_name_2 WHERE id = '% textbox1.text %'
UNION
SELECT product, 'Table_name_3' as table FROM Table_name_3 WHERE id = '% textbox1.text %'

关于mysql - 如何使用选择查询查找表名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23040872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com