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 7440475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:51:30+00:00 2026-05-29T10:51:30+00:00

I am at loss to figure out how to do an UPDATE with CASE

  • 0

I am at loss to figure out how to do an UPDATE with CASE and JOIN. This example is from my Drupal database. content_type has nid as its primary key; term_node, on the other hand, can have multiple rows with the same nid matched to different tids. MySQL will happily parse a query based on WHERE:

UPDATE `content_type`
LEFT JOIN `term_node` USING(nid)
 SET
  `field_m03` = 1
   WHERE tid = 696;

The above updates all rows in content_type which have an nid matched to (tid = 696) in term_node, as it should.
But when I try to string several conditions with CASE it won’t work. No errors, but 0 rows affected:

UPDATE `content_type`
LEFT JOIN `term_node` USING(nid)
 SET
  `field_m03` = (CASE
   WHEN (tid = '696') THEN '1'
   WHEN (tid = '697') THEN '2'
   WHEN (tid = '698') THEN '3'
   WHEN (tid = '699') THEN '4'
   WHEN (tid = '700') THEN '5'
   ELSE `field_m03`
   END);

Also tried without the parentheses and single quotes, no change.

  • 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-29T10:51:31+00:00Added an answer on May 29, 2026 at 10:51 am

    Your syntax seems correct.

    If your MySQL server has safe updates (SQL_SAFE_UPDATES) turned on, then your server will abort any updates that don’t have a WHERE or LIMIT clause.

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

Sidebar

Related Questions

I'm struggling to figure out what should be excluded from functional tests (in my
I'm at a loss trying to figure out why I have Actions that are
I wonder if someone here can help me figure out this problem. I need
So I'm attempting to figure out where my cross-compatibility issue is - From what
I'm at a loss, I can't see the reason something as simple as this
I'm at a loss why this loop stops after the first item. Can someone
Simple issue but I'm at a loss to debug this further. I followed the
I'm sorta at a loss to why this doesn't work considering I got it
I'm trying to figure out how to do the equivalent of an IPV4 broadcast
I'm trying to figure out how to get the name of the Facebook user

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.