- 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?
- 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)
You can simply do:
NOTwill switch0to1and vice versa.2)
You can use
COALESCE()in conjunction withCONCAT():—
If at least one item in
CONCAT()isNULL, thenCONCAT()will returnNULLregardless of any other item in its parameters.COALESCE()outputs the first non-NULLparameter.—
So if
nameisNULL, thenCONCAT()will returnNULL, andCOALESCE()will outputHello Guestinstead.