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

The Archive Base Latest Questions

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

I have a MySQL query that looks like this: UPDATE `Table` SET `Column` =

  • 0

I have a MySQL query that looks like this:

UPDATE `Table` SET `Column` = 
    CASE 
      WHEN `Option Id` = '1' THEN 'Apple'
      WHEN `Option Id` = '2' THEN 'Banana'
      WHEN `Option Id` = '3' THEN 'Q-Tip'
    END 

An my table currently looks like this:

Option Id | Column
        1 |      x
        2 |      x

I’d like it to result in:

Option Id | Column
        1 |  Apple
        2 | Banana
        3 |  Q-Tip

But it doesn’t insert the Q-Tip row. I’ve looked up and read a bit about INSERT ON DUPLICATE KEY UPDATE and REPLACE, but I can’t find a way to get those to work with this multiple row update using CASE. Do I have to write a separate query for each row to get this to work, or is there a nice way to do this in MySQL?

Option Id is not a Key itself, but it is part of the Primary Key.

EDIT Some more info:

I’m programming in PHP, and essentially I’m storing an array for the user. Option Id is the key, and Column is the value. So for simplicities sake, my table could look like:

User Id | Option Id | Value
     10 |         1 | Apple
     10 |         2 |  Shoe
     11 |         1 |  Czar
...

That user can easily update the elements in the array and add new ones, then POST the array to the server, in which case I’d like to store it in the table. My query above updates any array elements that they’ve edited, but it doesn’t insert the new ones. I’m wondering if there is a query that can take my array from POST and insert it into the table without me having to write a loop and have a query for every array element.

  • 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-25T06:29:51+00:00Added an answer on May 25, 2026 at 6:29 am

    This should work, if Option_Id is a primary key:

    REPLACE INTO `Table` (`Option_Id`, `Column`) VALUES
    (1, 'Apple'),
    (2, 'Banana'),
    (3, 'Q-Tip');
    

    The statement means: Insert the given rows or replace the values, if the PK is already existing.

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

Sidebar

Related Questions

So, I have a mysql table that looks roughly like this, where the first
I have a MySQL table that looks like this: Table: Designer id: integer name:
I have a table with a row that looks like this: ( 20091231 48498429,
I have a MySQL query that returns a result with a single column of
I have a MySQL query like this: SELECT *, SUM(...some SQL removed for brevety)
I have a MySQL database that looks similar to this: ID Group Name 1
I have an INSERT statement that looks like this: INSERT INTO officer (officer_number, name,
I have a MySQL query that I use to retrieve random rows from a
I have a MySQL (v 5, MyISAM) query that returns different rows depending on
I have a MySQL query in which I want to include a list of

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.