3

I have two tables ie., Table1 and Table2. The only difference between these tables is that Table2 contains extra columns creation_date and last_updated_date. Every week, Table1 records gets updated/inserted. These changes need to be reflected in Table2. We use Table2 to get latest records using max(last_updated_date). So, we want a query to compare two tables and make necessary changes in Table2 based on Table1. Thanks in advance.

7
  • If a record was updated in table 1 and there was no timestamp saved, how would the query know of that updated record to update table2? Why not use Triggers Commented Nov 21, 2014 at 6:11
  • Hi Hannky. Thanks for Your comment.Table1 with 2k+ records and weekly once some fields of records get updated. Table2 also contains 2k+ records. Just we need to compare it with Table1 for changed records and need to update them and change last_updated_date. We are thinking to implement this requirement using PHP and Mysql. Commented Nov 21, 2014 at 6:33
  • Why not add the columns to table 1? creation date can be current time and last updated can have an ON UPDATE clause to update when the row is updated! Commented Nov 21, 2014 at 6:44
  • Hi BarbiePylon. Thanks for comment. Yes you are correct but our requirement is limited so we cant keep those two columns as you stated Commented Nov 21, 2014 at 6:53
  • 2
    @Naruto So this is what you're doing after your series has ended? Commented Nov 21, 2014 at 7:27

1 Answer 1

1

Based on your query you can refer these links,hope it helps.

http://www.mysqltutorial.org/compare-two-tables-to-find-unmatched-records-mysql.aspx

Compare two SQL tables and return missing ids?

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much Atif Shaikh for solution. Link 1 is the solution for my problem. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.