Take the 2-minute tour ×
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. It's 100% free, no registration required.

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
1  
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
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.