How to get 0 from a query when no data is found for a criteria

baba

Registered User.
Local time
Today, 14:49
Joined
Nov 15, 2011
Messages
39
Hi, I am trying to run the below query. It fetches records when the select criteria is satisfied, however when no records are matched, I would like the query to display 0 .Please help!
Code:
select distinct(cars) from tbl1,tbl2 where tbl1.col1 =tbl2.col2 and tbl2.col2 is not null and tbl1.col3 not in (1,2,3,4) 
and tbl2.col4 = '2013.09'
Thanks !
 
Run an aggregate function instead, like Count() something or Sum() something. Count() the cars that satisfy the condition, like ...
Code:
SELECT Count(*) FROM Cars WHERE ....
Your query doesn't do math that might result in a zero, it selects records, or fails to.
Cheers,
 

Users who are viewing this thread

Back
Top Bottom