I am working with PostgreSQL 8.4.4. I want to fetch record from table based on multiple conditions as,
1) check if record exists
2) if exists then -> if type_id is 1 then select name if type_id is 2 then select name, abbreviation
3) if record not exits then print as 'Missing'
Following is the query for the same
select case when exists (select NAME || ' ' || ABBREVIATION from CONTACTS_COMPANY where id = 15) then ( select case when type_id = '1' then (select UPPER(NAME) from CONTACTS_COMPANY where id = 15) when type_id = '2' then (select UPPER(NAME) || ' ' || UPPER(ABBREVIATION) from CONTACTS_COMPANY where id = 15) end ) else UPPER('MISSING') end
When firing above query I am getting error as
ERROR: column "type_id" does not exist
LINE 7: when type_id = '1'
I am not getting what exactly is causing error. Any help would be appreciated. Thanks in advance!