开发者

Nested MySQL select statements within the select clause

Is there a way to use a sub select statement, which returns a list of column names, to be used in the 'select expression' in an outer mySQL expression?

eg

select (
    sub select that returns a comma开发者_Python百科 separated list of column names
) 
from table1;

In case your wondering how I get the comma separated list of column names, my sub select statement is somethign like...

SELECT group_concat(COLUMN_NAME) FROM information_schema.`COLUMNS` 
where table_name = 'table2' group by TABLE_NAME


You have to solve this using PREPARE and EXECUTE, as explained here: How To have Dynamic SQL in MySQL Stored Procedure

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜