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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:54:28+00:00 2026-06-02T23:54:28+00:00

I have a question regarding SQL syntax and whether or not a particular action

  • 0

I have a question regarding SQL syntax and whether or not a particular action is possible in a single query. Consider the following example:

Let’s say we have a Recipe table. Every recipe has 5 ingredients listed under columns ingredient1, ingredient2, etc. Let’s also say that suddenly sugar is determined to be unhealthy for you and every Recipe must replace ‘sugar’ with ‘artificial sweetener’ in every ingredient column where it exists. The problem I’ve run into is that there is no Ingredient table, thus every ingredient is listed literally under one of five columns rather than reference something like an ingredient ID.

How can I write the following (pseudo) query, if possible?

UPDATE Recipe 
    (SET ingredient1 = 'artificial sweetener' WHERE ingredient1 = 'sugar') OR
    (SET ingredient2 = 'artificial sweetener' WHERE ingredient2 = 'sugar') OR
    (SET ingredient3 = 'artificial sweetener' WHERE ingredient3 = 'sugar') OR
    (SET ingredient4 = 'artificial sweetener' WHERE ingredient4 = 'sugar') OR
    (SET ingredient5 = 'artificial sweetener' WHERE ingredient5 = 'sugar')

I have found multiple articles online about setting a column to a certain value based on its current value, but not for only setting (specific) columns that contain a value. Any help is greatly appreciated.

  • 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-02T23:54:29+00:00Added an answer on June 2, 2026 at 11:54 pm

    A CASE expression will dictate whether each of the five columns need to be modified. Use a WHERE clause to filter out any rows that don’t require modification:

    UPDATE Recipe
    SET ingredient1 = CASE WHEN ( ingredient1 = 'sugar' )  
        THEN 'artificial sweetener' ELSE ingredient1 END ,
    SET ingredient2 = CASE WHEN ( ingredient2 = 'sugar' )  
        THEN 'artificial sweetener' ELSE ingredient2 END ,
    SET ingredient3 = CASE WHEN ( ingredient3 = 'sugar' )  
        THEN 'artificial sweetener' ELSE ingredient3 END ,
    SET ingredient4 = CASE WHEN ( ingredient4 = 'sugar' )  
        THEN 'artificial sweetener' ELSE ingredient4 END ,
    SET ingredient5 = CASE WHEN ( ingredient5 = 'sugar' )  
        THEN 'artificial sweetener' ELSE ingredient5 END
    WHERE 'sugar' IN 
      ( ingredient1, ingredient2, ingredient3, ingredient4, ingredient5 )
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Me and my colleagues have a question regarding SQL Server 2008 query length and
I have a question regarding an SQL syntax. I have a mysql table like
I have a very general question regarding the use of LINQ vs SQL to
I have a question regarding locking in TSQL. Suppose I have a the following
I have a question regarding left join on SQL: I would like to know
I have a couple of question's regarding the following project. *Scott, Recently some developers
I have a simple question regarding T-SQL. I have a stored procedure which calls
I have a question regarding LINQ to SQL. I would like to write the
I have a question regarding performance of SQL Server. Suppose I have a table
I have a question regarding the online Google cloud lab @ http://code.google.com/apis/sql/docs/developers_guide_java.html at the

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.