MySQL REPLACE rows WHERE field a equals x and field b equals y <p>I'm trying to construct a 'new comments' feature where the user is shown the number of new comments since the last visit. I've constructed a 'Views' table that contains the topic id, the user id and a timestamp. What's the best way of updating the timestamp every time the user visits that topic or inserting a fresh row if one doesn't exist? At the moment I have:</p> <pre><code>REPLACE INTO Views (MemberID, TopicID, Visited) SET ('$_SESSION[SESS_MEMBER_ID]', '$threadid', '$t') WHERE MemberID = $_SESSION[SESS_MEMBER_ID] AND TopicID = $threadid </code></pre> <p>However, this does not work. Is it possible to do this in one query?</p>