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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:24:05+00:00 2026-06-08T07:24:05+00:00

How to swap the same columns value ? table_name id value 1 0 2

  • 0
  1. How to swap the same columns value ?

table_name

id    value

1      0

2      1

3      0

4      1

How to Change the values 0 to 1 and 1 to 0 using mysql query?

  1. How to print the following o/p ?

table_name

id name

1   x

2   y

3   NULL

If the name contains value it should print as “Hi X” else if the name is NULL it should print as “Hello Guest”.

My O/P should be like below

name

Hi X

Hi y

Hello Guest

How can this be done ?

Thanks in advance….

  • 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-08T07:24:07+00:00Added an answer on June 8, 2026 at 7:24 am

    1)

    You can simply do:

    SELECT id, NOT value AS value
    FROM tbl
    

    NOT will switch 0 to 1 and vice versa.


    2)

    You can use COALESCE() in conjunction with CONCAT():

    SELECT COALESCE(CONCAT('Hi ', name), 'Hello Guest') AS name
    FROM tbl
    

    —

    • If at least one item in CONCAT() is NULL, then CONCAT() will return NULL regardless of any other item in its parameters.

    • COALESCE() outputs the first non-NULL parameter.

    —

    So if name is NULL, then CONCAT() will return NULL, and COALESCE() will output Hello Guest instead.

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

Sidebar

Related Questions

How do I swap keys and values in a Hash? I have the following
I am trying to swap the values for elements name and cmt in a
I was asking b4 about swapping query to swap data between rows in same
I have a need to swap between different DB instances of the same design.
Why would the following swap action fail at random times? int i,p,a[11] = {0,1,2,3,4,5,6,7,8,9,10
I'd like to swap out an sql:query for some Java code that builds a
Is it possible to change the way Vim names its swap/backup/undo files? To avoid
I am trying to swap b/w few images using jquery. There are couple of
I would like to swap classes in two links using jQuery. I got a
I have this fairly straightforward table with ID , Position , Name columns. ID

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.