Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 994575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:35:46+00:00 2026-05-16T06:35:46+00:00

Having a bit of a special moment here. Basically I have a DB table

  • 0

Having a bit of a “special” moment here. Basically I have a DB table for listing files and their attributes (size, creation date, etc). Being a self-proclaimed (borderline delusional) SQL-whiz, you can imagine my surprise when I failed to figure out a quality manner by which to individually list only files whose [INSERT ATTRIBUTE HERE] appeared multiple times.

For instance, say I wanted to see all files whose file size (or creation date) appeared more than once in the table, but I still wanted them listed separately. Or an even better application: a group of files that share MD5 hashes, but only ones that appear multiple times (i.e. duplicates), and I still want to list each file independently. Obviously I could loop through the DB multiple times, but I’m interested in a single query. Any thoughts?

Best.

[EDIT #1 (error in count)]

select * 
 from @foo where FileNameOnDisk in (
     select FileNameOnDisk, count([INSERT_ATTRIBUTE_HERE]) as num from @foo 
     group by FileNameOnDisk 
     having num > 1
 )order by FileNameOnDisk
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:35:47+00:00Added an answer on May 16, 2026 at 6:35 am

    I’d approach it with the HAVING COUNT(someField) > 1. Here’s a sample using FileName, but you could of course modify it for the MD5 or the datetime field.

    declare @foo table (FileNameOnDisk varchar(100), MD5Hash varchar(100), CreatedOn smalldatetime)
    
    INSERT Into @foo (FileNameOnDisk, MD5Hash, CreatedOn)
     VALUES ('foo', 'abc123', 'jan 1 2010'),
      ('bar', 'abc123', 'aug 1 2010'),
      ('ar', 'ajkfsd43', 'nov 1 2010'),
      ('baz', '44', 'sep 1 2010'),
      ('foo', 'abc123', 'aug 1 2010'),
      ('baz', '44', 'jan 1 2010')
    
     select * 
     from @foo where FileNameOnDisk in (
         select FileNameOnDisk from @foo 
         group by FileNameOnDisk 
         having COUNT(FileNameOnDisk) > 1
     )order by FileNameOnDisk
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a bit of a problem here. We have 2 urls let me
I'm having a bit of a problem. I have a datatable in the parent
We're having a bit of fun here at work. It all started with one
having a bit of a problem with a recent project. The goal here is
I'm having a bit of a problem. I'm using FireFox 3.6 and have the
Having a bit of a brain freeze on how to do this. I have
Having a bit of a problem here on a matrix multiplication code. I seem
Having a bit of trouble here. I've created a custom ImageView by subclassing ImageView
i am having a bit of trouble with DataInputStreams, So i have data coming
I'm having a bit of problem with casting and datagrids. I have a LINQ

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.