Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mySQL select differences between two tables in different databases

I have two databases: old and new.
Both have a comments table. There are 100 comments in the old table that are not in the new. Comments have been added to the new table and there is a conflict in IDs so querying by ID will not be an option. I need so isolate the 100 comments that that they can be exported and inserted into the new database.

I know there are 100 because I have tried using some mysql data compare tools. Unfortunately all of those tools just want to update the comments in the new table with the old content.

Is there a query I can run to get the 100 comments?

like image 471
Jason Yost Avatar asked May 30 '11 23:05

Jason Yost


People also ask

Can I query from two different databases?

Doing so is made a lot easier by software that can accommodate multiple database connections. That's where Navicat Premium comes in. It's a database development, administration and management tool that allows you to simultaneously connect to MySQL, MariaDB, MongoDB, SQL Server, Oracle, PostgreSQL, and SQLite databases.


1 Answers

Assuming the tables aren't very large you can run something like this:

SELECT *
FROM OldDatabase.CommentTable
WHERE COMMENT NOT IN
    (SELECT COMMENT
     FROM NewDatabase.CommentTable)
like image 165
Dave Maple Avatar answered Oct 31 '22 02:10

Dave Maple