Solved

MySQL: Finding Oldest Douplicate

Posted on 2014-02-11
3
251 Views
Last Modified: 2014-02-11
The returns the bookkey and updated time of duplicate items:
SELECT elqBooks.isbn, elqBooks.updated
 FROM elqBooks 
 GROUP BY elqBooks.ISBN HAVING count(elqBooks.isbn) > 1

Open in new window

I want the OLDEST item to be selected.  How can I get the OLDEST matching duplicated item?
0
Comment
Question by:hankknight
3 Comments
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39850012
SELECT elqBooks.isbn, MIN(elqBooks.updated)
 FROM elqBooks
 GROUP BY elqBooks.ISBN HAVING count(elqBooks.isbn) > 1
0
 
LVL 16

Author Comment

by:hankknight
ID: 39850068
Thanks.  Now how can I do this with the bookkey only?  I only want the bookkey of the oldest douplicate record to be included.
SELECT elqBooks.bookkey
 FROM elqBooks 
 GROUP BY elqBooks.ISBN HAVING count(elqBooks.isbn) > 1

Open in new window

0
 
LVL 11

Expert Comment

by:John_Vidmar
ID: 39850188
Without knowing your schema, would you be able to take the results of the group-by/min and join back to your table to get the key?
SELECT	a.bookkey
FROM	elqBooks	a
JOIN	(	SELECT	isbn
		,	updated = MIN(updated)
		FROM	elqBooks 
		GROUP
		BY	isbn
		HAVING	count(*) > 1 
	)	b	ON	a.isbn = b.isbn
			AND	a.updated = b.updated

Open in new window

0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now