Jump to content

[SOLVED] Dynamic Table Names


Recommended Posts

Does `table` in `SELECT * FROM table` have to be a constant.. or can the table be a dynamically generated value based on another tables column value.


SELECT concat('prefix_', tbl_name) FROM where_table_names_are_stored WHERE id = $id


I woud like to select from the above return value as a table name rather than a result set in one query.


Any ideas?

Link to comment
Share on other sites

While I can't answer your question, I can suggest using CASE to choose between tables.  Or partitioning may suit your needs, if you are splitting the tables for efficiency rather than for design reasons.  Looks like partitioning in MySQL was only introduced in 5.1.  Partitioning is very powerful when used appropriately.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.