Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6765245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:41:23+00:00 2026-05-26T14:41:23+00:00

I have an SQL UPDATE statement using the compound primary key ( Key1,Key2 )

  • 0

I have an SQL UPDATE statement using the compound primary key (Key1,Key2) of a table that looks something like this:

UPDATE TableName SET FieldName = CASE 
WHEN (Key1=389 AND Key2=5594091315209354374) THEN 1320243147187 
WHEN (Key1=397 AND Key2=8686441440518828409) THEN 1320243147562 
WHEN (Key1=389 AND Key2=5717973625907258381) THEN 1320243147182 
.... 
WHEN (Key1=394 AND Key2=5512452777552926025) THEN 1320243147389 END 
WHERE Key2 IN (123782199165241826,5594091315209354374,...,3553840348728167644) 
AND Key1 IN (400,394,391,389,397); 

I might have, say, 20 or so WHENs in the CASE statement.

How might MySQL say this has updated slightly more rows than there are WHENs?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:41:24+00:00Added an answer on May 26, 2026 at 2:41 pm

    Your CASE statement has nothing to do with which rows are affected. It’s entirely up to your WHERE clause:

    WHERE Key2 IN (123782199165241826,5594091315209354374,…,3553840348728167644)
    AND Key1 IN (400,394,391,389,397);

    Every row that fits those conditions will be updated. The question, then, is what happens to the rows that don’t match a CASE condition?

    For this part I’m not 100% sure what MySQL will do, as I’m more of a sql server guy. I suspect, however, that your CASE statement results in NULL, which is then assigned to FieldName. It’s also possible that MySQL will decide not to change anything, but I would still expect it to report all the rows that match your WHERE clause as updated.

    You should probably have an ELSE FieldName at the end of your case statement to be certain you get the latter behavior (no change) rather than the former (set to NULL).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using T-SQL, I would like to execute an UPDATE statement that will SET columns
I have a SQL table like so: Update: I'm changing the example table as
Assume that we have this SQL statement: UPDATE article SET saison='12E', mode='ECH', client='SAS', WHERE
I have a SQL update statement I am running from inside a PHP program.
I have the following SQL statement where i'm trying to update multiple rows matching
I have an UPDATE sql command that modifies a Date/Time field in a particular
I have an SQL query that takes the following form: UPDATE foo SET flag=true
I have SQL update query problem. I would like to be able to update
Using this SP I keep getting an error on the UPDATE statement indicating that
I have this SQL update query: UPDATE table1 SET table1.field1 = 1 WHERE table1.id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.