php - Is there a way to make a table name dynamic in a query? -


i trying create class-inheritance design products.

there base table contains common fields. each product type there separate table containing fields product type only

so in order data product need join base table whatever table correlates product_type listed in base table. there way make query join on table dynamically?

here query try illustrate trying do:

select * product_base b inner join <value of b.product_type> t     on b.product_base_id = t.product_base_id  b.product_base_id = :base_id 

is there way this?

no, there's no way this. table name must known @ time of parsing query, parser can tell if table exists, , contains columns reference. optimizer needs know table , indexes, can come plan of indexes use.

what you're asking table determined during execution, based on data found row-by-row. there's no way rdbms know @ parse-time all data values correspond real tables.

there's no reason implement class table inheritance. cti supports true references between tables.

you're instead describing antipattern of polymorphic associations.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -