Say I've modeled the inheritance in this manner (table per class):
http://www.agiledata.org/essays/mappingObjects.html#MapEachClassToTable

I'm having a tough time figuring out how to join a (subclass's) table
whose name comes from a column value.

Assuming this is the right way to go about it, how would I join the
Person superclass to the Employee subclass?

Person
------------------------------------------
ID  Name           Type
1   Jamie Jackson  Employee <-- used in join
------------------------------------------

Employee
------------------------------------------
ID  Salary
1   1000000.00
------------------------------------------

I can't just do...
SELECT t1.Name, t2.Salary
FROM Person t1 LEFT JOIN Employee t2 t1.Id = t2.Id
WHERE t1.ID = 1          ^^^^^^^^
... Since I don't know the ("Employee") table name until after a
query.

Is there a SQL (preferably vanilla) trick to doing this dynamic join
in a single query, or do I have to use multiple queries (or sprocs)?

Alternatively, should I wimp out and use views (which would likely be
reused for reporting)?

Thanks,
Jamie
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to