Created
          April 23, 2012 06:21 
        
      - 
      
 - 
        
Save sgronblo/2469091 to your computer and use it in GitHub Desktop.  
    Multi column/row update with a single query for mysql
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | UPDATE table | |
| SET col1 = CASE id | |
| WHEN id1 THEN id1_v1, | |
| WHEN id2 THEN id2_v1 | |
| END | |
| col2 = CASE id | |
| WHEN id1 THEN id1_v2, | |
| WHEN id2 THEN id2_v2 | |
| END | |
| WHERE id IN (id1, id2) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment