Posted: Tue Jul 31, 2007 5:33 pm
I'm fine with SQL Queries being as complicated as can be, no problems there.. this can be termed in 2 different ways:
1: the diagrams ^^^up there, show what I'd like to do
2: I'm just a little frustrated that you can't SELECT * FROM (SELECT table_name FROM LinkTable WHERE LinkId = 12); <<this is what I "really" want to achieve..
with regards 2; it is possible, but the only way you can do it in mysql is by using a prepared statement as such:
I just typed that off the top of my head by the way so don't shoot me down if there's a syntax error in there!
1: the diagrams ^^^up there, show what I'd like to do
2: I'm just a little frustrated that you can't SELECT * FROM (SELECT table_name FROM LinkTable WHERE LinkId = 12); <<this is what I "really" want to achieve..
with regards 2; it is possible, but the only way you can do it in mysql is by using a prepared statement as such:
Code: Select all
@tab = SELECT table_name FROM LinkTable WHERE LinkId = 12;
@quer = CONCAT('SELECT * FROM ',@tab);
PREPARE my_query FROM @quer;
EXECUTE my_query;
DEALLOCATE PREPARE my_query;