SQL query dynamic table name in FOR

前端 未结 3 1479
耶瑟儿~
耶瑟儿~ 2020-12-19 07:11

I have a table tbl1 which has a column tbl_names. This column contains the name of some other tables.
Now I want to write a query in th

3条回答
  •  没有蜡笔的小新
    2020-12-19 07:14

    You can use prepared statements

    SET @a = (select tbl_names from tbl1);
    SET @x := CONCAT('SELECT * FROM ', @a);
    Prepare stmt FROM @x;
    Execute stmt;
    DEALLOCATE PREPARE stmt;
    

    PREPARE Syntax

    Cheers.

提交回复
热议问题