SELECT * FROM external_db WHERE order_id NOT IN internal_db

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

SELECT * FROM external_db WHERE order_id NOT IN internal_db

Post by Luke »

I need to import orders from an external database routinely. Every time somebody clicks "Synchronize DBs" I want to grab all order_ids that I don't already have? How should I go about this? It seems like an easy task... my first instinct was to just select all ids from my db and perform this query:

Code: Select all

SELECT * FROM external_db WHERE order_id NOT IN (@internal_ids)
I'm just wondering if there isn't a better way. Thanks! :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Useful posts has a thread on selecting stuff in one table that isn't in another.
User avatar
emmbec
Forum Contributor
Posts: 112
Joined: Thu Sep 21, 2006 12:19 pm
Location: Queretaro, Mexico

Re: SELECT * FROM external_db WHERE order_id NOT IN internal_db

Post by emmbec »

If your database is in SQL Server you could use a DTS, I don't know if it is more efficient, but it is very easy to do.
Post Reply