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

  • SEARCH
  • Home
  • 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 6896931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:06:21+00:00 2026-05-27T07:06:21+00:00

I have a MySQL UPDATE statement that uses a CASE clause UPDATE partsList SET

  • 0

I have a MySQL UPDATE statement that uses a CASE clause

UPDATE partsList SET quantity =  
CASE
  WHEN partFK = 1 THEN 4
  WHEN partFK = 2 THEN 8
END
WHERE buildFK = 1;

The above statement works. Yet when I remove one of the WHEN statements, it breaks and the error indicates the CASE clause isn’t returning anything. Is it that the CASE clause must have more than one WHEN to function.

I don’t know beforehand how many updates I’ll need, so I’m trying to build a single update statement that can handle one or many updates.

Thanks for any insights you can provide.

  • 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-27T07:06:22+00:00Added an answer on May 27, 2026 at 7:06 am

    It isn’t that the CASE must have more than one, WHEN...THEN, it’s that it must handle all the data you give it.

    If you removed one of the clauses, you leave a hole. e.g.

    UPDATE partsList SET quantity =  
    CASE
      WHEN partFK = 1 THEN 4
    END
    WHERE buildFK = 1;
    

    With this update statement, if parkFK is 2, then the update fails because the CASE can’t handle the input.

    You can either limit your source data by adding another line to your where-clause (e.g. AND partFK in (1,2)), or you could add an ELSE to the case expression.

    UPDATE partsList SET quantity =  
    CASE
      WHEN partFK = 1 THEN 4
      WHEN partFK = 2 THEN 8
      ELSE 12 
    END
    WHERE buildFK = 1;
    

    However, based on the SQL statement you’ve shown, there is probably a better way. Presumably, partFK is a foreign-key to some other table. Can you pull the value for quantity from there?

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

Sidebar

Related Questions

I need to have MySQL query like this one: UPDATE table_name SET 1 =
I have a heap based table in MySQL that I am trying to update
I have a couple of tables (mySQL) that i would like to update with
I have a MySQL insert statement that inserts data from an existing Despgoods table
the MySQL manual says that a CASE statement (the WHEN part) can contain a
I have a table that was created using this mysql statement below. CREATE TABLE
I have a problem with checking if a MySQL update statement succeeded. I want
I have an INSERT INTO ... ON DUPLICATE KEY UPDATE ... statement that executes
Currently, I am using an with ajax to update my mysql. Now, I have
I have a MySQL table with about 5,000,000 rows that are being constantly updated

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.