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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:52:21+00:00 2026-06-04T21:52:21+00:00

These two links are related to this question I guess, but I do not

  • 0

These two links are related to this question I guess, but I do not find a way out to solve my requirement which is slightly different.

I have a table, say like this:

fruit         color
--------------------
mango          red
apple          red
orange         yellow
banana         green

I need to UPDATE field color in such a way that red becomes yellow and yellow becomes red. Here is how the table should look like after update query.

fruit         color
--------------------
mango          yellow
apple          yellow
orange         red
banana         green

This query wont work obviously.

UPDATE plant SET color = 'yellow' WHERE color = 'red';
UPDATE plant SET color = 'red' WHERE color = 'yellow'

Thanks.

  • 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-06-04T21:52:22+00:00Added an answer on June 4, 2026 at 9:52 pm

    You can do it in a single query:

    UPDATE plant 
    SET    color = IF(color = 'yellow', 'red', IF(color = 'red', 'yellow', color))
    WHERE  color IN ('red', 'yellow');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basic question but I couldn't find any related topics answering exactly what I need.
Slightly related to this question , but you don't really need to read that.
I'm having the same problem issued in these two links: one , two .
In this question I am looking for links/code to handle an IList<OrderLine> in an
I have two problems related to my implementation - I need a function which
My question is related about disabling links/click events with jQuery, and it's probably easier
This question is related to this older one: Isotope Grid layout use empty space
The Original Question I realized I am not 100% sure why this behaves the
note: this question is related to PostGIS and Postgresql and is implemented with PHP
I have these two lines in my web.xml <url-pattern>/</url-pattern> : Index Servlet and <url-pattern>/login</url-pattern>

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.