ahs10 Posted April 14, 2009 Share Posted April 14, 2009 UPDATE db.temp_tbl AS temp, db.live_tbl AS curr SET curr.delete = 0 WHERE temp.name = curr.name AND temp.number = curr.number if the name and number of each row are the same in both tables, delete is set to 0. however my attempts to reverse this statement, changing it to a negative, fail miserably... UPDATE db.temp_tbl AS temp, db.live_tbl AS curr SET curr.delete = 1 WHERE temp.name != curr.name AND temp.number != curr.number i know how to do this in php, but was hoping to do it in my query. would it be best to get the results into php and run it through a loop for comparison of these two fields? Link to comment https://forums.phpfreaks.com/topic/154078-solved-whats-the-opposite-of-this-query/ Share on other sites More sharing options...
ahs10 Posted April 14, 2009 Author Share Posted April 14, 2009 so after some investigation, i found i wasn't really asking the right question =) i found a possible solution. is this working like i think it works? i want to set `delete` = 1 for each row that has a different name or number in the two tables. however, number can also be NULL... as long as it is NULL in both tables, it's good. UPDATE db.live_tbl AS curr LEFT OUTER JOIN db.temp_tbl AS temp ON (curr.name = temp.name AND curr.number = temp.number) SET curr.delete = 1 WHERE temp.name IS NULL AND temp.number IS NULL AND curr.number IS NOT NULL Link to comment https://forums.phpfreaks.com/topic/154078-solved-whats-the-opposite-of-this-query/#findComment-809985 Share on other sites More sharing options...
ahs10 Posted April 14, 2009 Author Share Posted April 14, 2009 wow, not only am i talking to myself, but i'm answering myself too. isn't that a sign of mental illness? ha ha.... my last attempt was not correct. here's the query that i confirm works for my needs, in case it can help someone else out.... UPDATE db.live_tbl AS curr LEFT OUTER JOIN db.temp_tbl AS temp ON (curr.name = temp.name AND curr.number = temp.number) SET curr.delete = 1 WHERE temp.name IS NULL OR temp.number != curr.number Link to comment https://forums.phpfreaks.com/topic/154078-solved-whats-the-opposite-of-this-query/#findComment-810026 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.