Skip to main content

how to use CASE,WHEN and ELSE statesman in mysql

 make sure are created other wise create your table and add some data.

for example : 


 then run this query:

SELECT first_name, last_name, 

( CASE  

        WHEN user_id < 3 THEN "Admin user" 

        WHEN user_id = 3 THEN "editor user" 

        ELSE  "suscriber user" 

END) as role 

FROM users;  

the result output is :



you can define query as per your requirement.

Comments

Popular posts from this blog

Minimum and maximum number with - and + 500 in Mysql and Sql query and Find out table scheema of our database in Mysql and sql query and Find out all table name of our database in Mysql and sql query and Find out current date and time in mysql and sql help of sql query

Minimum and maximum number with - and + 500 in Mysql and Sql query:- syntax:-  SELECT MIN(Used)-500 , max(Used)+500 FROM audit Find out current date and time in mysql and sql help of sql query:- syntax:- SELECT now() Find out database name in Mysql and sql query:- syntax:-  SELECT DATABASE(); Find out all table name of our database in Mysql and sql query:- syntax:- SHOW TABLES; Find out   table scheema   of our database in Mysql and sql query:- syntax:- DESCRIBE <table name>;

Wordpress Database tabel Description image

Wordpress Database tabel Description image