Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to update multiple row in single mysql query

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 543
    Comment on it

    Hello friends,

    Most of time we need to update multiple row at a time or in single mysql query, So most of developer use iterate the update query and execute many time. This is not good practice. We should use syntax given as below.

    For Example:-

    UPDATE table_users
        SET cod_user = (case when user_role = 'student' then '622057'
                             when user_role = 'assistant' then '2913659'
                             when user_role = 'admin' then '6160230'
                        end),
            date = '12082014'
        WHERE user_role in ('student', 'assistant', 'admin') AND
              cod_office = '17389551';

      In this case we use mysql CASE and THEN syntax.

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: