Search code examples
sqlitesubquerytablename

sqlite - subquery for table name


I use SQLite. How can I use something like this:

INSERT INTO (
    SELECT `table_name`
    FROM `tables`
    WHERE `id`=1)(`data_column_name`)
VALUES ('some data')

Thanks for help


Solution

  • According to the documentation you cannot. The INSERT statement takes a table name - with an optional schema name - not an expression.

    You would have to evaluate the SELECT and then build the INSERT statement.