mysql - query in query


How is it possible to do the following : (i am using mysql - phpmyadmin )

this query returns a table name :

Select table_name from Table1 where id = 1

I want to use it inside another query , like :

select val from (Select table_name from Table1 where id = 1)

but this sure does not work, and since phpmyadmin does not support calling stored procedures, could there be any possible solution for this ?

You cannot really do it in a single SQL statement.

You are trying to use data (field value) as metadata (table name), and SQL does not allow this.

You could break it in two statements or write dynamic SQL in a stored procedure. Note that not all client layers support returning resultsets from stored procedures.