Hi.. welcome to my blog at “We Are Knowledge”.. In here you
will getting amany IT knowledge, from desktop programming until web programming
you can get it.. You can take it Free, so you must readcthis article in order
to you having IT knowledge about it..
Still with tutorial about “MySQL” and now, I want giving you
IT knowledge about “Condition In MySQL”.. You know it ?? if do not, let’s do
read this article..
Condition in mysql is syntax used for doing selection from
many options, and we must choice I (one) from many options. Likely other
program language, condition in MySQL also using “IF”.
In MySQL to be found 3 (three) conditions, namely :
1. IF;
2. IF ELSE and;
3. CASE
Ok .. I want start from number 1 (one) until number 3
(three)
1. IF
Statement if used if only 1 (one) option or condition. If
the value is right then getting result. And this general form :
IF select_condition THEN
Your_command_if_condition_is_right;
END IF;
Example 1 :
IF x > 5 THEN
Set sal = ‘biggest’;
END IF
2. IF ELSE
Statement “IF ELSE” used if you having more than one
condition or option.
General form :
IF select_condition THEN
Your_command_if_condition_is_true;
ELSE
Your_command_if_condition_is_false;
END IF;
Example 2:
IF x > 5 THEN
Set sal = ‘biggest’;
ELSE
Set sal = ‘smallest’;
END IF
3. CASE
Likely if command, this syntax also for choice one option
from other options. But usually this syntax used if you having many options,
and if the condition has been true then program direct exit without execute
other command.
General form :
CASE select_expression
WHEN value THEN
Write_statement_1;
[WHEN value THEN
Write_statement_2 … ]
Example 3:
CASE
WHEN (sal > 10) THEN
SET commission = 200;
WHEN (sal > 5) THEN
SET commission = 100;
WHEN (sal > 2) THEN
SET commission = 50;
ELSE SET commission = 20;
END CASE;
Ok just it..
Thanks was reading my article…
See you later..
No comments:
Post a Comment