Re: [GENERAL] determining which table to lookup depending on data values

2006-12-18 Thread David Fetter
On Sun, Dec 17, 2006 at 08:14:43PM +1300, Steve Castellotti wrote: > >Hello all- >I'm working with a poorly-designed schema and need to do a lookup in > one >table who's name I have to pull from a second table. I'm wondering if its >possible to do something like this in Postgr

Re: [GENERAL] determining which table to lookup depending on data

2006-12-17 Thread Richard Huxton
Steve Castellotti wrote: SELECT name FROM (SELECT table_name FROM media WHERE media_id=1); You can try something like: SELECT name FROM audio JOIN media ON id WHERE table_name='audio' AND media_id=1 UNION ALL SELECT name FROM video JOIN media ON id WHERE table_name='video' AND media_id=1 ; As