skip to Main Content

I’m trying to think of the most efficient way to check if data from one table has changed in another. Ex:

Table a

id      name        age
111     John        30
222     Jill        32

Table b

id      name        age
111     John        30
222     Jill        33
333     Jacob       35

Here we can see that data for 1 row has changed i.e for id 222.

2

Answers


  1. SELECT id, name, tableA.age old_age, tableB.age new_age
    FROM tableA
    JOIN tableB USING (id, name)
    WHERE tableA.age <=> tableB.age
    
    Login or Signup to reply.
  2. You just need to join them using the your key:

    SELECT a.id, a.name, a.age, b.name, b.age
    FROM table_a a
    JOIN table_b b 
        ON a.id = b.id
        AND (a.name <> b.name OR a.age <> b.age)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search