Help needed for "Distinct"!

Help needed for "Distinct"!

Post by Santos » Sat, 20 Apr 2002 00:54:32



Friends,

When I use this Query I get Duplicate Records even though I have used the
"Distinct" keyword.
Does Distinct key word work in Joins?

Any Help would be Appreciated.

SELECT
Distinct(dbo.QORAccounts.ID),dbo.QORAccounts.CompleteDate,dbo.QORAccounts.Co
mpany,dbo.QORAccounts.ContactID,dbo.QORAccounts.ExecID,dbo.QORAccounts.Statu
s,dbo.QORAccounts.RegistrationType, dbo.QORAccounts.Suspend,
dbo.QORAccounts.DateAdded, dbo.Organizations.Registered,
dbo.Organizations.DateRegistered FROM dbo.QORAccounts LEFT JOIN
dbo.Organizations ON dbo.QORAccounts.ContactID =
dbo.Organizations.ContactMemberID where
dbo.QORAccounts.RegistrationType<>'OA' And dbo.QORAccounts.ContentControlID
= 209 Order By dbo.Organizations.DateRegistered asc;

--

Regards,
Santosh

 
 
 

Help needed for "Distinct"!

Post by Anith Se » Sat, 20 Apr 2002 01:04:13


When you have a LEFT JOIN, there is a chance for NULLs to be returned in the
resultset.
Hence DISTINCT on NULLs will not give you the results you want.

Hope it helps
Thanks
Anith


Quote:> Friends,

> When I use this Query I get Duplicate Records even though I have used the
> "Distinct" keyword.
> Does Distinct key word work in Joins?

> Any Help would be Appreciated.

> SELECT

Distinct(dbo.QORAccounts.ID),dbo.QORAccounts.CompleteDate,dbo.QORAccounts.Co
mpany,dbo.QORAccounts.ContactID,dbo.QORAccounts.ExecID,dbo.QORAccounts.Statu
Quote:> s,dbo.QORAccounts.RegistrationType, dbo.QORAccounts.Suspend,
> dbo.QORAccounts.DateAdded, dbo.Organizations.Registered,
> dbo.Organizations.DateRegistered FROM dbo.QORAccounts LEFT JOIN
> dbo.Organizations ON dbo.QORAccounts.ContactID =
> dbo.Organizations.ContactMemberID where
> dbo.QORAccounts.RegistrationType<>'OA' And

dbo.QORAccounts.ContentControlID
Quote:> = 209 Order By dbo.Organizations.DateRegistered asc;

> --

> Regards,
> Santosh


 
 
 

Help needed for "Distinct"!

Post by James Morto » Sat, 20 Apr 2002 01:42:23


Use a subquery

SELECT
 Distinct QORAccounts.ID
FROM
(select QORAccounts.ID,dbo.QORAccounts.CompleteDate,dbo.QORAccounts.Co

mpany,dbo.QORAccounts.ContactID,dbo.QORAccounts.ExecID,dbo.QORAccounts.Statu
s,dbo.QORAccounts.RegistrationType, dbo.QORAccounts.Suspend,
 dbo.QORAccounts.DateAdded, dbo.Organizations.Registered,
 dbo.Organizations.DateRegistered FROM dbo.QORAccounts LEFT JOIN
 dbo.Organizations ON dbo.QORAccounts.ContactID =
 dbo.Organizations.ContactMemberID where
 dbo.QORAccounts.RegistrationType<>'OA' And dbo.QORAccounts.ContentControlID
 = 209 Order By dbo.Organizations.DateRegistered asc)

James M


Quote:> Friends,

> When I use this Query I get Duplicate Records even though I have used the
> "Distinct" keyword.
> Does Distinct key word work in Joins?

> Any Help would be Appreciated.

> SELECT

Distinct(dbo.QORAccounts.ID),dbo.QORAccounts.CompleteDate,dbo.QORAccounts.Co
mpany,dbo.QORAccounts.ContactID,dbo.QORAccounts.ExecID,dbo.QORAccounts.Statu
Quote:> s,dbo.QORAccounts.RegistrationType, dbo.QORAccounts.Suspend,
> dbo.QORAccounts.DateAdded, dbo.Organizations.Registered,
> dbo.Organizations.DateRegistered FROM dbo.QORAccounts LEFT JOIN
> dbo.Organizations ON dbo.QORAccounts.ContactID =
> dbo.Organizations.ContactMemberID where
> dbo.QORAccounts.RegistrationType<>'OA' And

dbo.QORAccounts.ContentControlID
Quote:> = 209 Order By dbo.Organizations.DateRegistered asc;

> --

> Regards,
> Santosh