PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 23, 2022

[FIXED] How to combine the below the update querys into one, Update multiple rows with multiple values for same column and the rest of data with other value

 October 23, 2022     mysql, sql, sql-update     No comments   

Issue

here i want to change the date for 9 rows

1.

UPDATE forum_topic_resume 
SET _When_Updated = (now() -INTERVAL 6 day) 
WHERE _id IN (96250, 69081, 69555)
UPDATE forum_topic_resume 
SET _When_Updated = (now() -INTERVAL 8 day) 
WHERE _id IN (70494, 68612, 69564, 69660, 72437, 80498)

The change the status

3.

UPDATE forum_topic_resume 
SET _Status = 1224 
WHERE _id IN (96250, 69081, 69555)
UPDATE forum_topic_resume 
SET _Status_Is = 1228 
WHERE _id IN (70494, 68612, 69564)
UPDATE forum_topic_resume 
SET _Status_Is = 1229 
WHERE _id IN (69660, 72437, 80498)

There are about 52 more Ids for whom I was to set the status to a different value which would look like below.

6.

UPDATE forum_topic_resume 
SET _Status_Is = 1250 
WHERE _id IN (for the rest of the ids)

Solution

One way is using multiple case conditions:

UPDATE forum_topic_resume  
SET  _When_Updated  =  CASE 
                        WHEN _id IN (96250, 69081, 69555) THEN (now() -INTERVAL 6 day)
                        WHEN _id IN (70494, 68612, 69564, 69660, 72437, 80498) THEN (now() -INTERVAL 8 day)
                        other id conditions  ............. 
                        END,
_Status  = CASE             
             WHEN _id IN (96250, 69081, 69555) THEN 1224 
             WHEN _id IN (70494, 68612, 69564) 1228 
                         ......
             END,
_Status_Is = CASE           
              WHEN _id IN (96250, 69081, 69555) THEN 1224 
              WHEN _id IN (70494, 68612, 69564) 1228 
                         ......
              END;  


Answered By - Ergest Basha
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing