Ask Your Question
0

How to use a query to pull out records which exist in one table but not the other

asked 2016-02-09 17:58:06 +0200

TheDatabaseGuy gravatar image

How can I use a query to pull out records which exist in one table but not the other?

An SQL Inner Join will only find records that DO match in both. A Left or Right Join will pull out ALL records from one table.

Basically I have two identical structured tables, most records appear in both tables but table 2 has extra records and possibly a few records which, while existing in table 1, have been updated.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2016-02-11 14:33:11 +0200

pierre-yves samyn gravatar image

Hi

I'm not sure I understand the question correctly, sorry if not...

The following query selects records which exist in TableB and not in TableA:

SELECT "IdTable" FROM "TableB" WHERE "IdTable" NOT IN ( SELECT "IdTable" FROM "TableA" )

The following query updates field NbJours inTableA with value of same field in TableB when IDs match:

UPDATE "TableA" SET "NbJours" = (SELECT "NbJours" FROM "TableB" WHERE "TableA"."IdTable" =  "IdTable")

HTH

Regards

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-02-09 17:58:06 +0200

Seen: 322 times

Last updated: Feb 11 '16