Welcome to WebmasterWorld Guest from 54.90.119.59

Forum Moderators: open

Message Too Old, No Replies

REPLACE INTO. (if tableA.updated > tableB.updated?)

     
3:37 am on Feb 11, 2017 (gmt 0)

Preferred Member

Top Contributors Of The Month

joined:Mar 15, 2013
posts: 570
votes: 47


I have 2 tables with identical structures, and the last column is "updated". Column "updated" is timestamp on update CURRENT_TIMESTAMP.

tableB collects "flagged" data submitted from users, for a moderator to review before moving it to tableA (if approved).

Here's the code I currently use:


@var_user = 'whatever';

REPLACE INTO tableA
SELECT * FROM tableB
WHERE username=@var_user
LIMIT 1;


Can you guys suggest how I might change it to only REPLACE if tableB.updated is newer than tableA.updated? Keeping in mind that tableA.updated may not exist at all.

TIA!