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!
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!
can you please clarify if there is 1 (or more) field(s) that could help to "choose" which row to take?
Hi,
In your case you just have to use the "distinct keyword", like this:
SELECT DISTINCT yourColumns FROM yourTable
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?
can u describe more...? can u give small example?
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
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
from your table
group by acct_no
having count(acct_no)=1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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.
ASKER
Thank you for the quick response, it worked great!