×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Need to compare two tables and list the differences

Need to compare two tables and list the differences

Need to compare two tables and list the differences

(OP)
I have two identical tables in two different DBs. In the one I will be adding data, once all finished the I need will copy all that data to the other db.table. Later on I want to run a query to see if there has been any additions to the first table. Comparing the two tables seems to me the way to go. I am trying to catch someone adding data to the first table. I kinda have a query but it doesn't show the "New" additions to the first table which are not in the second table.

CODE -->

select id, user, description,tech
       from (
           select id, user, description, tech
           from test.devices
           union all
           select id, user, description, tech
           from test1.devices)
       temp
       group by id, user, description,tech
       having count(*)>1 

This code shows all the entries in the first table, even though there is a different entry than in the second table.

Help??

Thanks

RE: Need to compare two tables and list the differences

Hi

Instead of union all you will need except.

Quote (EdLentz)

I am trying to catch someone adding data to the first table.
That sounds more like a task for triggers instead.

Feherke.
feherke.github.io

RE: Need to compare two tables and list the differences

(OP)
Hi feherke

Thanks for replying. I briefly looked up triggers. Looks interesting. That would tell me if someone inserted into the table for sure. I would also want to know "What" they inserted. I will try the except and see if I can make that work

Thanks again

Ed

RE: Need to compare two tables and list the differences

(OP)
I figured out how to use the trigger to update a table, Works sweet. Now to send an email telling of the new record.

Thanks!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close