April 11, 2007 at 3:31 pm
please help me on this one too,...
query1 returns 1569803 rows
query2 returns 1350056 rows
why is this happening?? aren't these similar queries,... please help
-- query 1
select count(*)
from nameaddr_ac addr, recipients rec
left outer join RecipientDistType dist on
rec.idaccount = dist.idaccount and
dist.cdedoctype='INV'
where
rec.idaccount = addr.id_account
and rec.cdeRecipientType = 'Market'
-- query2
select count(*)
from nameaddr_ac addr, recipients rec
left outer join RecipientDistType dist on
rec.idaccount = dist.idaccount
where
rec.idaccount = addr.id_account
and rec.cdeRecipientType = 'Market'
and (dist.cdedoctype='INV' or dist.cdeDocType IS NULL)
thanks,
vidya
April 11, 2007 at 3:47 pm
No they are not the same.
The first one only returns rows where dist.cdedoctype equals 'INV'.
The second one returns rows where dist.cdedoctype equals 'INV' OR has a NULL value.
The first one won't count NULLs.
-SQLBill
April 11, 2007 at 4:47 pm
thanks for the quick reply
but this is my question
this is the query i have on my older version of SQL
select count(*)
from nameaddr_ac addr, recipients rec, RecipientDistType dist
where
rec.idaccount = addr.id_account
and rec.idaccount*=dist.idaccount
and rec.cdeRecipientType = 'Market'
and dist.cdedoctype='INV'
what should be the equivalent for this in the latest version of SQL ???
thanks,
vidya
April 11, 2007 at 5:54 pm
I don't think mixing syntax is a good idea.
Try to make it consistent:
select count(*)
from nameaddr_ac addr
INNER JOIN recipients rec ON rec.idaccount = addr.id_account and rec.cdeRecipientType = 'Market'
left outer join RecipientDistType dist on rec.idaccount = dist.idaccount and dist.cdedoctype='INV'
_____________
Code for TallyGenerator
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply