Hello everyone,

I have to query a table according to the current item being fetched in the select statement.

What I meant, I want to form the name of the table and query it on runtime. For example, there is an item that comes from items table and it has a title and there is a table has the name : units_{title} contains informations about these kind of items.

Is there any ideas to do that with mysql statement without the need to do PHP code?


Edited by osm1987: n/a

6 Years
Discussion Span
Last Post by debasisdas

I never found a way to do that. You can use a case statement which lists all the allowed table names and chooses the right one depending on a procedure input parameter, but I don't think that you can have truly dynamic table names in stored procedures or queries.


Actually selecting the table and field names should be handles from front end application and the same need to be passed into back end and the database procedure should process the input parameters to process the job.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.