Solved

MySql Data Restore

Posted on 2011-09-14
2
220 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
2 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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