Jump to content

[SOLVED] What's the opposite of this query?


Recommended Posts

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.