Solved

MySQL: Finding Oldest Douplicate

Posted on 2014-02-11
3
248 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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

13 Experts available now in Live!

Get 1:1 Help Now