Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • MySQL "IF" function

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 281
    Comment on it

    The function that returns a value based on a condition is MYSQL IF function. Hence MYSQL IF function is one of the control flow functions.

    The syntax of the MySQL IF function is as follows:

    IF(expr,if_true_expr,if_false_expr)
    

    For example, If we have a table "address" with the column "userid, city, state, country" in which some state values are NULL. We want to print 'N/A' where the state value is null.

    SELECT userid, city, IF(state IS NULL, 'N/A', state) state,  country FROM  address;
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: