Solved

MySQL: Finding Oldest Douplicate

Posted on 2014-02-11
3
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 35

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

737 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