Jump to content

How to view only rows with duplicate values in a table


Gianni
 Share

Recommended Posts

Referring to a question posted here, this is a possible SQL query that should do:

supposed you have an sqlite table named 'multimedia' with a column named 'sha1_hash', and you want to see only rows with the 'sha1_hash' value that appears more than one time within the table, you could use an SQL query like this:

SELECT sha1_hash, COUNT(sha1_hash) AS sha1_sum FROM multimedia GROUP BY sha1_hash HAVING sha1_sum>1 ORDER BY sha1_sum DESC;

this query should show only records with the value of sha1_hash that appears more times also in other records, showing it only one time, with a column indicating how many occurrences are present, ordered from the most recurring to the least recurring one.

I don't know if this query can be simplified a bit...?,

.... if there is a simpler way I would like some hint,
Thanks

Edited by Chimp
corrections in title and text

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

29 minutes ago, Danp2 said:

That's how I would do it. Not sure how you could get any simpler...

.... thanks .... :)

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

What will happen to all items with same hash? Obviously there must remain one item and the rest deleted?

-- original

SELECT sha1_hash, COUNT(sha1_hash) AS sha1_sum FROM multimedia GROUP BY sha1_hash HAVING sha1_sum>1 ORDER BY sha1_sum DESC;

-- my take
--delete from multimedia
select sha1_hash from multimedia
where id not in ( select min(id)
from multimedia
group by sha1_hash )

Yes / No / Maybe ?

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...