Sql group by

TyB

Well-known member
Joined
May 14, 2009
Messages
102
Programming Experience
3-5
Hello, all

I have a table that has 3 columns.

name
path
hash

Now I know that there are duplicate records. I want to return all the records and I want to group them by the column that will show the duplicates which is the hash field. I want all the records returned and I want the duplicate records grouped together then the non duplicate records. So the return would look something like this.

file1 c: 1009
file4 d: 1009
file2 c: 2553
file7 c: 2553
file3 c: 4545
file5 c: 6575
file6 e: 8989

Any help with the select statement would be appreciated.

Thanks,

Ty
 
You didn't say what database you are using so I put brackets around name and path. Name, for sure, is a reserved word, and path may be as well. Try something like this
VB.NET:
SELECT [name], [path],  COUNT(hash)
FROM yourtablename
GROUP BY hash
HAVING COUNT(hash) > 1
 
wrong function

Thanks hack for the sample. It's not quiet right as it throws errors than the other columns are not in the aggregate however, I realized that I was using the wrong function for what I wanted and was making it harder than it needed to be.

Here is what works.

VB.NET:
"SELECT * FROM dups WHERE hash > '' ORDER BY hash DESC"

Thanks,
Ty
 
Back
Top