Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- MySQL dynamic table name within query
May 16, 2006, 4:27 pm
rate this thread
name that is a variable? This does not work but gives an example:
SELECT * FROM concat('table', 'name')
- OR -
SET @table = 'a';
SELCT * FROM @table
Of course the query can be constructed dynamically but does not exactly
fit the needs. The situation is very complicated and would just be
confusing to discuss here so please do not offer suggestions on how to
construct the query programically as that will not work for this
Re: MySQL dynamic table name within query
Table names, column names, etc. cannot be dynamic in the way you
describe. This is not permitted by the SQL language, for many reasons.
For instance, there would be no way for the query optimizer to decide
which index(es) to use, if it doesn't know at parse time which tables
and columns are being queried.
Find another way to solve your problem.
- » Americanas.com SALDO de TVs Com at 80% de Desconto (29798)
- — Newest thread in » MySQL Database Forum