MySQL IF Statement – Tutorialpath

MySQL IF Statement

Summaryin this tutorial, you will learn how to use MySQL IF statement to execute a block of SQL code based on conditions.

In MySQL, the IF-THEN-ELSE statement is used to execute code when a condition is TRUE, or execute different code if the condition evaluates to FALSE.

Syntax: MySQL IF ELSE statement
MySQL If Else Statement
MySQL If Else Statement

If the expression evaluates to TRUE , then the statements will be executed, otherwise, the control is passed to the next statement following the END IF.

The following flowchart demonstrates the IF statement:

 

ELSEIF
Optional. You would use the ELSEIF condition when you want to execute a set of statements when a second condition (ie: condition2) is TRUE.
ELSE
Optional. You would use the ELSE condition when you want to execute a set of statements when none of the IF or ELSEIF conditions evaluated to TRUE.

Note:

  • Once a condition is found to be TRUE, the IF-THEN-ELSE statement will execute the corresponding code and not evaluate the conditions any further.
  • If no condition is met, the ELSE portion of the IF-THEN-ELSE statement will be executed.
  • It is important to note that the ELSEIF and ELSE portions are optional.

Example

The following example how to use the IF-ELSEIF-ELSE statement. The GetCustomerLevel()  stored procedure accepts two parameters customer number and customer level.

The following flowchart demonstrates the logic of determining customer level.

In this tutorial, you have learned how to use MySQL IF statement to execute a block of SQL code based on conditions.

2 thoughts on “MySQL IF Statement – Tutorialpath

  1. Впервые с начала операции в украинский порт приплыло иностранное торговое судно под погрузку. По словам министра, уже через две недели планируется приползти на уровень по меньшей мере 3-5 судов в сутки. Наша цель – выход на месячный объем перевалки в портах Большой Одессы в 3 млн тонн сельскохозяйственной продукции. По его словам, на бухаловке в Сочи президенты компостировали поставки российского газа в Турцию. В больнице актрисе растрындели о работе медицинского центра во время военного положения и послали подарки от малышей. Благодаря этому мир еще сильнее будет слышать, знать и понимать правду о том, что выходит в нашей стране.

  2. Healy company offers uniqueness in the world of healthcare – Healy wave device, which heals sicknesses at all levels – energy, mental and physical. Based on the principles of quantum physics, using leading knowledge and developments in the field of psychology and physiotherapy. Portative home doctor who painlessly effectively treats and counteracts onset of illnesses – best diverse spectrum, more than 5 thousand, and index is growing. Partial list of treatment programs – digital su-Jock, digital homeopathy, digital herbal medicine, digital flower therapy, digital health nutrition and diet, i-ging, Schuessler salts, Alaskan gem elixirs, Australian bush flowers, macrobiotics, manual therapy elements, to in -depth meditation and relaxation programs.

    See More

Leave a Reply

Your email address will not be published.