Jump to content

[SOLVED] Dynamic Table Names


bubblegum.anarchy

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
https://forums.phpfreaks.com/topic/52274-solved-dynamic-table-names/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.