I need to generate the table name for the FROM clause on-the-fly. I can do it by building a string and then using that, but I really need to do it in a JOIN clause if possible.
NOTE! I did
NOT design this structure, it is an inherited project.
Here is a basic example of what I need:
Code:
select foo from CONCAT('regtable_',(select regtable from event where id = ?));
The simplified schema looks like this:
Code:
Table event:
id - int,
regtable - int
Table regtable_1:
regid - int,
eventID - int,
foo - varchar
Table regtable_2:
regid - int,
eventID - int,
foo - varchar
Currently I have to select the regtable field from the event table, build a string from that and then use that string. I would like to do it all in a single SQL statement if possible. (And I am not sure at all that this is possible).
Thanks in advance!
Jim