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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:42:26+00:00 2026-05-19T01:42:26+00:00

I have been doing some searching but have not been able to find an

  • 0

I have been doing some searching but have not been able to find an answer for this so thought I would ask here as the people here know everything 🙂

I am trying to combine these 2 update queries into one query.

UPDATE addresses SET is_default='0' WHERE id!='1'
UPDATE addresses SET is_default='1' WHERE id='1'

I assume this should be too hard to accomplish but i cant seem to work it out 🙁

Thanks

Paul

  • 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-19T01:42:27+00:00Added an answer on May 19, 2026 at 1:42 am

    You can use CASE to do this:

    UPDATE addresses SET is_default = CASE WHEN id = 1 THEN 1 ELSE 0 END;
    

    In your example, you’re updating the entire table, so you wouldn’t benefit from indexes no matter what, but if you were only doing a subset of values, you’d still want to leave the where in (because its very doubtful the optimizer could figure out how to use the index). For example:

    UPDATE foo
      SET
        bar = CASE id WHEN 1 THEN 1 WHEN 2 THEN 0 ELSE bar END
        baz = CASE WHEN id = 3 THEN 7 ELSE baz END
      WHERE id IN (1,2,3)
    

    (Note the two different CASE syntaxes).

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

Sidebar

Related Questions

I have been searching here for some time but haven't been able to find
I have done some searching and i can not find any function thats doing
I have been doing some research on test driven development and find it pretty
I am sure this is a silly question, but I have been searching for
I have been doing some Winsock programming lately. I do not do much stuff
I have been searching for best practice, but I did not found it. I
I've been searching around trying to find an answer both here and google, although
I have been doing some research for using MSMQ. Following 2 gave me fundamental
I have been doing some x86 programming in Windows with NASM and I have
So I have been doing some research into getting my UTF8 to print correctly.

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.