?
Solved

MySql Data Restore

Posted on 2011-09-14
2
Medium Priority
?
225 Views
Last Modified: 2012-05-12
I recently had to restore a backup and to say the least it went bad.  I have missing records.  I now have two tables one is a good backup of the originally lost data (loanFindingReplace) and a live table that has some, but not all of the original findings.  I can not just replace the current live table (loanFinding) since I have had number entries since the restore.  How is the easiest/quickest query to determine which records don't exist in the loanFinding table that do exist in the loanFindingReplace table and insert those into loanFinding?  Both tables have the same fields with the same names.  Fields
Thank you.
0
Comment
Question by:rcowen00
[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
2 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 36540868
Hi.

Sorry to hear about the failed restore. That can be a pain in the tail. To answer your question, I would start with a NOT EXISTS clause.

It works in general as:

SELECT {column list}
FROM TableA
WHERE NOT EXISTS (
   -- don't need to actually return data, so literal 1 is fine.
   SELECT 1 
   FROM TableB
   WHERE TableB.UniqueColumn = TableA.UniqueColumn
)
;

Open in new window


In your case, that may look like:
SELECT loanFindingKey
FROM loanFindingReplace r
WHERE NOT EXISTS (
   SELECT 1
   FROM loanFinding l
   WHERE l.loanFindingKey = r.loanFindingKey
)
;

Open in new window


Note: you may need to look at some other data that identifies a match if it is possible that you have duplicate auto_number values for non-matching rows due to the data lost. If not, then should be as simple as above.

Hopefully that helps!

Kevin
0
 

Author Closing Comment

by:rcowen00
ID: 36540963
Thank you.
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 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