MYSQL query using variable as table name in LEFT JOIN

后端 未结 2 1771
眼角桃花
眼角桃花 2020-12-06 11:29
SELECT var1,var2,var3,table_name 
FROM table1 LEFT JOIN table_name on var3=table_name.id

Meaning I want to dynamically left join table, depending o

2条回答
  •  情深已故
    2020-12-06 11:51

    Table names, as well as column names, can't be dynamic in an SQL query. So you have to apply your logic programmatically, using 2 queries, or with a stored procedure, see an example here: http://forums.mysql.com/read.php?98,126506,126598#msg-126598

提交回复
热议问题