Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to check for duplicate row data

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2013-01-24 : 10:02:38
How to check duplicate rows based on these columns: 259k rows are in teh table.
Is it possible to see a count based on teh combination of all fields, to se how many rows are there.

select table_name, active, businessunitid, cost_center, glacct, glsubacct from LAW_DEL_IMGNOW_GLACCT_CHG;


Thank you very much for the helpful info.

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-01-24 : 11:11:31
You can use the row_number function or group by clause - in the example below, I am using group by. If you want to see only rows that have duplicates, uncomment the last line
select 
table_name, active, businessunitid, cost_center, glacct, glsubacct, COUNT(*) AS DupCount
from LAW_DEL_IMGNOW_GLACCT_CHG
GROUP BY
select table_name, active, businessunitid, cost_center, glacct, glsubacct from LAW_DEL_IMGNOW_GLACCT_CHG
-- HAVING COUNT(*) > 1
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-25 : 01:35:50
quote:
Originally posted by James K

You can use the row_number function or group by clause - in the example below, I am using group by. If you want to see only rows that have duplicates, uncomment the last line
select 
table_name, active, businessunitid, cost_center, glacct, glsubacct, COUNT(*) AS DupCount
from LAW_DEL_IMGNOW_GLACCT_CHG
GROUP BY
select table_name, active, businessunitid, cost_center, glacct, glsubacct from LAW_DEL_IMGNOW_GLACCT_CHG
-- HAVING COUNT(*) > 1



fixed typos

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-01-25 : 07:59:51
How embarrassing! Thank you Visakh.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-25 : 09:45:14
No problem..

It happens to all

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -