MySQL - is it possible to use a column as a tablename?
Suppose that we have, in mysql, a table "mytable"
with the columns: id, title, type
.
Is it possible to use its column as a table name in the same query?
For example:
SELECT m.id, m.title FROM mytable m INNER开发者_JS百科 JOIN m.type WHERE m.id=2
Where "type" will give me the name of the table to do the inner join.
No, Sorry :(
The closest you can get (afaik) is to cursor through your main table and write dynamic html for the join for each row. VERY slow.
Or, find a new design pattern - Is there scope for you to post a question about what you are trying to achieve and how people may go about that?
Why not put all of your type data in a single table ? and then partition the table by type.
精彩评论