Sunday, June 29, 2014

MYSQL SELECT CASE

MYSQL SELECT CASE:


In Mysql Case is like normal switch case in java, we can use for different results to display in select query.
Use case:

Here we have the table tab1

from this table cname column 
  •  if a represents we have to display as apple 
  • Null represents display as NA
  • others display as it is.





SQL QUERY :

SELECT id,case

when  cname='a'  THEN 'APPLE'

when cname IS NULL THEN 'NA'

 else cname end  FROM tab1 ;

RESULT: