Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In MYSQL. I want to select the records which has the same contents with the table name.

for example, consider the following table.

<TABLE : tbl_1>
| id    | no   |
| admin |    1 |
| guest |    2 |
| tbl_1 |    3 |

In this case, I want to select the 3rd record. How can I do this with a single select query?

select * from tbl_1 where id=(name of table);

I can't use select * from tbl_1 where id='tbl_1' since the table name will be decided during runtime.

P.S I can't access information_schema database.

thank you in advance

share|improve this question
If you can do select * from tbl_1 why it is any more difficult to do select * from tbl_1 where id='tbl_1'? This probably indicates bad design anyway though. – Martin Smith Nov 6 '13 at 11:30
If the table name will be decided during runtime, then construct the query during runtime (I guess I say the same as @MartinSmith above, only with different words.) I agree, this does not look like a good design. – ypercubeᵀᴹ Nov 6 '13 at 12:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.