Select query based on column names stored in another table

Names of the tables are stored in my another table due to the fact i have quite a big MySQL table having more than 100 columns. Now i want to get the column names like:

select (select a,b,c) from tableB from tableA How can i do it by using one select query.

Can you please post the output of a SHOW CREATE TABLE for both the tables?

What information is required from the tables?

Thanks for the reply.
My one table has more than 100 columns which are difficult to paste here but i can explain in bit more details with the below example:

Table A has physical fields:


Column1, Column2, Column3, Column4, Column5 and so on

Table B has the names of these columns stored as records.

Query should be Select Column1, Column2, Column3 from Table A if i want to select 3 columns from table A but i don’t know the column names from Table A as my column names map table is Table B so what i want is to get the column names from Table B and then use in the select of Table A as:

Select (select * from Table B where id>5) from Table A

Query works find with one row but in case of multiple rows it doesn’t as due to the fact that it needs commas in between columns names and i can make it workable as:

Select (select Column1 from Table B),(select Column2 from Table B),(select Column3 from Table B) from Table A

But i want to make it workable like:

Select (select * from Table B where id>5) from Table A

you can’t do it in one query, you will have to use two – one to retrieve the colulmn names, and then your actual query with the column names incorporated

but before you get too far down this road, let me caution you that this design is fraught with danger, and there are probably other ways of accomplishing whatever it is you’re trying to accomplish, which you didn’t explain

If table B is just being used to store the field names for table A then you should rename all the fields in A to what they’re meant to be (the names in table B) so that instead of table A having fields like:

Column1, Column2, Column3, Column4, Column5…

it should be like:

id, name, email… (or whatever the field names are meant to be)