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 2000 Forums
 SQL Server Development (2000)
 dumb question...distinct..

Author  Topic 

eddie
Starting Member

45 Posts

Posted - 2002-01-07 : 10:52:43
Ok, I am sure this is easy to do I am just having a brain cramp. I know you can use distinct to show all distinct rows in a table but what if I have 40,000 rows and I want to find the rows that are not distinct..my current colution is to make a temp table and insert distinct into that table then I can check to see what rows are in one table but not the distinct but is there an sql statement I can run to find the rows where a certain column value is not distinct?

Thanks,
Eddie

Nazim
A custom title

1408 Posts

Posted - 2002-01-07 : 10:58:40
select column1,column2,column3,....,count(*)
from tablename
group by column1,column2,column3,....
having count(*)>1



HTH


----------------------------
Anything that Doesn't Kills you Makes you Stronger

Edited by - Nazim on 01/07/2002 10:59:42
Go to Top of Page

BMurray4321
Starting Member

4 Posts

Posted - 2002-01-07 : 11:05:04
Try this

SELECT <<Column Name>>
FROM <<Tabl Name>>
HAVING COUNT(DISTINCT (<<Column Name>>)) > 1
ORDER BY <<Column Name>>

Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2002-01-07 : 18:47:53
Eddie, how much "not distinct" are they? Is this another way of saying, "how do I remove duplicates?" If so, read Graz'a article here: [url]http://www.sqlteam.com/item.asp?ItemID=3331[/url]

--------------------------------------------------------------
1000 Posts, Here I come! I wonder what my new title will be...
Go to Top of Page
   

- Advertisement -