How to return a text response using DECODE or CASE when "0 results"?
I am trying to return a simple response, either 'Yes' or 'No' (in Oracle 9i), via two different SQL queries:
Here is my data:
schema.table1 a
user_iD-------privilege
1--------------2
schema.table2 c
user_id-----username
1------------JOE
2------------JAMES
Here are my queries:
SELECT DECODE (c.username,'JOE','YES','NO') BID_PRIV
FROM schema.table1 a, schema.table2 c
WHERE a.privilege = 2
AND a.user_id = c.user_id
and c.USERNAME = 'JOE';
SELECT DECODE (c.username,'JAMES','YES','NO') BID_PRIV
FROM schema.table1 a, schema.table2 c
WHERE a.privilege = 2
AND a.user_id = c.user_id
and c.USERNAME = 'JAMES';
The first query returns a YES. The second query returns 0 results, since JAMES does not have Privilege = 2 (he has no records in that schema.table1). I want the second query to return a 'NO'. I've tried using a NULL, but that didn't work.
I also tried CASE but that too seems to have a problem when you get No Results.
Any ideas?