【发布时间】:2020-05-05 13:12:27
【问题描述】:
我在 mysql 中有一个名为“tables”的表,该表包含所有表名和表 id 的名称。
我需要对此表进行 INNER JOIN 并替换值 {table} 和 {column_id}
SELECT *
FROM attributes_categories AS ac
INNER JOIN attributes_codes AS aco ON aco.id_attribute_code =
ac.attributes_codes_id_attribute_code
INNER JOIN {$table} AS b
LEFT JOIN translations AS t ON t.id = b.{$column_id}
我正在尝试这样的事情,但是,我无法替换“INNER JOIN {$table}”,因为我无法插入结果来代替表名:
SELECT COLUMN_NAME
FROM attributes_categories AS ac
INNER JOIN attributes_codes AS aco ON aco.id_attribute_code =
ac.attributes_codes_id_attribute_code
INNER JOIN tables AS tab ON tab.id_table = ac.tables_id_table
INNER JOIN INFORMATION_SCHEMA.TABLES ON TABLE_NAME = tab.table
INNER JOIN tab.table AS b
LEFT JOIN translations AS t ON t.id = b.column_id
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA='knskjhpumw1'
结果是:
Mensagens do MySQL :
#1146 - Tabela 'tab.table' does not exist
谢谢!
【问题讨论】:
标签: php mysql mariadb inner-join database-schema