List:General Discussion« Previous MessageNext Message »
From:Michael Fischer Date:November 8 2006 2:56am
Subject:Slightly bizzare query strategy
View as plain text  
Ok, here's one. Either its impossible, or someone might
be able to point me to the light.


* A table TABLE_DESC, which is rather like a system table,
in that it contains the names and column_names of other tables.

* A table MY_TABLE, which contains "ordinary" data, and has a set
of rows in TABLE_DESC.

What I wish to do is to do 


but without knowing that the name of the table is "MY_TABLE" in advance
of submitting the query to the db, but rather discovering its name
from TABLE_DESC in the same query. 

Perhaps this can be done with some combination of setting variables
within a function or procedure, and views, but I haven't been able
to work out a way to do it yet. 

The minimal

set @tname := (SELECT table_name FROM table_desc WHERE id = :id);
SELECT * FROM @tname; 

certainly doesn't work....although @tname does contain the expected value.

Playing games with subqueries has been equally unsuccessful.

Thanks in advance.

Michael Fischer                         Happiness is a config option.
michael@stripped                        Recompile and be happy. 
Slightly bizzare query strategyMichael Fischer8 Nov
  • Re: Slightly bizzare query strategyDan Nelson8 Nov