Forum Moderators: open

Message Too Old, No Replies

Pass select expr from subquery

Is it possible?

         

cdmn

9:17 am on Nov 30, 2007 (gmt 0)

10+ Year Member



Really simple question, is it possible to pass SELECT expr. as a result from subquery?

Smth like this:

SELECT
(
SELECT GROUP_CONCAT(column_name)
FROM table1
WHERE id IN ('1', '2')
)
FROM table2

Of course subquery returns whats expected "column1, column1", but the root query does not understand this string as a SELECT expression. Maybe there is some sort of EVAL function? to try to help query to understand the string as a portion of query?

Thanks!

cdmn

10:53 am on Dec 1, 2007 (gmt 0)

10+ Year Member



Anyone? :-)

ZydoSEO

9:55 pm on Dec 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have to do this all inside of a single SQL statement? If you're using asp or SQL then you could run the subquery first getting back the column list. Then build a SQL string something like:

sql = "SELECT "+columnlistfromSubQuery+" FROM TABLE2"

And then execute the sql statement...

cdmn

10:00 am on Dec 2, 2007 (gmt 0)

10+ Year Member



Yes, i could run subquery as a separated query and then pass the result to root query :-)

But im kinda trying do this just with one query...

Maybe its imposibble?