October 27th, 2003, 08:07 PM
like case but for the whole query
Ok I've been checking out a lot of different options and haven't found what I need. Maybe I'm just not looking at this correctly.
SELECT field1 FROM table WHERE field2 = 'something' AND field1 = 145
but if 145 doesn't exist I want it to run a view and have the results from the view be in place of 145.
I know it's not very clear ask questions I'll try to explain more.
October 27th, 2003, 08:25 PM
I may not be understanding correctly, but it sounds like your problem could be solved with a UNION between your first case of when field1 = 145 and your second case, when field1 ISNULL or doesn't = 145. Can you post the table setup and more about what you want from the query?
PostgreSQL, it's what's for dinner...
October 28th, 2003, 01:54 AM
Ok let me try to explain better.
CREATE TABLE mytable (
id SERIAL PRIMARY KEY,
name CHARACTER VARYING NOT NULL,
aid INTEGER NOT NULL
I want to
SELECT * FROM mytable WHERE aid = 145
now if that quey fails I want it to run
SELECT * FROM mytable WHERE aid = 43
I can do this programticly but I assume it can be done within the query also. OR isn't good because it returns both and I need only one record returned.
I tried UNION but it didn't do what I need. Hope this is clearer thanks for the help.
October 28th, 2003, 07:50 AM
I can't think of a way to do this with simple SQL. Why not write a function in pl/pgsql to do this? Then it'd be as simple as:
October 28th, 2003, 08:01 AM
WHERE aid = 145
where not exists
where aid = 145)
and aid = 43
October 28th, 2003, 11:26 AM
Thank you thank you very much swampboogie works perfectly. Thanks to all of you for your help.