开发者

wrong mysql query syntax

if for example this query returns a table name called "invoice" :

select table_name from Table1 where table_ID = 2

how can I put this query inside a bigger one ?

So instead of :

insert into invoice values (1,1,1)

I want to write :

insert into (select table_name from Table1 where table_ID = 2) values (1,1,1)

but this gives an error, can anyone tell me the right syntax开发者_高级运维 thanks in advance


You cannot replace a table name with a subquery. It's not possible to do what you want in a SQL query.

If your RDBMS supports stored procedures, you can write one which produces a SQL query from a string using the results of your SELECT query as part of that string, then execute it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜