• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

SQL question

imported_jediknight

Senior member
Need to create a query as above. How can I do this in DB2?

My thought is:
SELECT not exists (select * from table) as answer;

But that doesn't work. The only other thing I can think of is something along the lines of:
select 'true' as answer
from t
where c=999 and 5 in (1,2,3)
union
select 'false' as answer
from t
where c=999 and 5 not in (1,2,3);
(NB: t is a table that has one entry where c=999)

But something similar (using exists, not exists) for my query above seems like a real hack.. and I think there should be a better way to accomplish this.

Thanks..
 
SELECT CASE WHEN c = 999 AND 5 in (1,2,3) THEN 'True' ELSE 'False' FROM t

Although, what is "5 in (1,2,3)". Surely 5 is not a valid column name ...
 
Originally posted by: MrChad
SELECT CASE WHEN c = 999 AND 5 in (1,2,3) THEN 'True' ELSE 'False' FROM t

Although, what is "5 in (1,2,3)". Surely 5 is not a valid column name ...


Thanks. Surely, 5 is not a column name.. it's just there for demonstration purposes.. the whole query is much longer (and rather pointless to post).
 
I've never dealt with DB2, but this works on MS SQL Server.

SELECT CASE
WHEN COUNT(*) > 0 THEN 'True'
ELSE 'False'
END
AS answer
FROM t
 
Rather than having it return true or false, what I do when I code in PHP and MySQL is I simply have it check how many rows were returned. If > 0, then that is the same as false for your example.
 
Back
Top