No Rows found

UDA
GLB
Fan

No Rows found

How do i perform a no rows check in a simple sql query?

I need to return 0 if i do not find a record for a given condition.

glb
4 REPLIES
Enthusiast

Re: No Rows found

Hi,

you can use

select * from mydatabase.mytable sample 1;

.if activitycount >0 then goto .continue_label

.exit 8;

cheers,
Novice
GLB
Fan

Re: No Rows found

Ok i need this in a simple query, i can't do it through Unix or Mainframe.
Another thing is , for a set of conditions the exhaustive list have to return 5 rows instead returns only 3 rows, that is when i need to throw out the 0.
rgs
Enthusiast

Re: No Rows found

Hmm, simple question, so I wonder whether you really mean that. It's simply:

select count(*) from mytable where .... ;

If there are no rows that match the where condition it will return zero otherwise it returns the number of rows that match you where condition.
GLB
Fan

Re: No Rows found

select * from a
join b
on ...
where ...

a has 10 rows and b has only 5 rows that match for the given key values and condition.

I need to get a 0 value if this is the case.

I got it done like

select a.*,cnt,count(b.col)
(
select * from a
join b
on ...
where
join
(select count(*) cnt from a)
)
group by a.*,cnt
having count(b.col) = cnt

But the query is complex and tables involved are huge. So i want to know if there is a better approach to it.