gpt4 book ai didi

mysql : table1 field value as name for table2

转载 作者:行者123 更新时间:2023-11-29 22:52:17 25 4
gpt4 key购买 nike

我有一个像这样的数据库:

Table1:
----------
id
id_item
tablename (enum: 'table2','table3','table4')

table2:
----------
id
value

table3:
-----------
id
value

table4: [...]

我想要一个类似这样的查询:

SELECT t1.id, t2.value FROM table1 AS t1
LEFT JOIN t1.tablename as t2 ON t1.id_item=t2.id

我尝试了“错误 1146 (42S02):表 't1.table' 不存在”

请任何人提出与此类似的查询或我重新使用的新格式

提前致谢。

最佳答案

SELECT t1.id, t2.value FROM table1 AS t1 LEFT JOIN t1.tablename as t2 ON t1.id_item=t2.id

为什么要将表名 tablename 与第一个表别名连接起来?

t1.表名

将查询修改为

SELECT t1.id, t2.value FROM table1 AS t1 LEFT JOIN tablename as t2 ON t1.id_item=t2.id
^Here

关于mysql : table1 field value as name for table2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28847756/

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