Link to home
Start Free TrialLog in
Avatar of mctc
mctc

asked on

Exclude duplicate records

Looking for a script to exclude duplicate records in a table.
I want the result to display only the single records, not the duplicated (account number) records in the table.
Additionally, I want to see if the account number records from another table,  match the single (account numbers) records in the above table.  
I have about 30 fields in the table w/duplicates
I am using SQL Server 2005.

Please help!

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

can you please clarify if there is 1 (or more) field(s) that could help to "choose" which row to take?
Avatar of BalkisBr
BalkisBr

Hi,

In your case you just have to use the "distinct keyword", like this:

SELECT DISTINCT yourColumns FROM yourTable
hi mctc,
 can u describe more...? can u give small example?
Avatar of mctc

ASKER

Select Distinct does not provide the intented results.
The result that I want returned from the query would be like below. I only want the account numbers that are not duplicated 100,103,104.
acct_no
100
102
102
102
103
104
 
select count(acct_no), acct_no
from your table
group by acct_no
having count(acct_no)=1
ASKER CERTIFIED SOLUTION
Avatar of Faizan Sarwar
Faizan Sarwar
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
According to your question this is the answer and if you create a table having value

acct_no
100
102
102
102
103
104

o/p = 100,103,104

then check this Query

select  acct_no
from account
group by acct_no
having count(acct_no)=1
I forgot to mention in the  above post that  :  "account " is my table name.
Avatar of mctc

ASKER

Thank you for the quick response, it worked great!