LEARNING PHP AND MYSQL (2015)
Operators in SQL
SQL operators are as follows.
Operator |
Description |
Example |
= |
Equal to |
John = ‘author’ |
<> |
Not equal to |
Dept<>height |
> |
Greater than |
100>6 |
< |
Less than |
6<100 |
≥ |
Greater than or equal |
Rate≥2.6 |
≤ |
Less than or equal |
Rate ≤2.6 |
BETWEEN |
In an inclusive range |
Range BETWEEN 10 AND 20 |
LIKE |
Match the character |
NAME LIKE ‘WILLY%’ |
IS OR IS NOT |
Compare to null |
AGE IS OR IS NOT RAJ |
IN |
Equal to one of the multiple possible value |
ID IN (100,120,134) |
AS |
Used to change name when viewing the result or the particular value |
Select student AS ‘section a’ |
IS NOT DISTINCT FORM |
Equal to value given or both are missing data |
Loan IS NOT DISTINCT FORM-APPLICABLE |
Conditions
SQL expression-
Case- It is one of the searching techniques of finding the matching case. It was used in SQL-92.
Example
CASE WHEN N > 0
THEN ‘POSITIVE VALUE’
WHEN<0
THEN ‘NEGATIVE VALUE’
ELSE
‘ZERO’
When- This condition is the source through which the data is compared with the output which is set is similar to its condition. That time the action which has to be take is defined using when the condition with the when statement is stated.
Example
CASE a
WHEN 1
THEN ‘ONE ORANGE’
WHEN 2
THEN ‘TWO ORANGES’
ELSE
‘CANNOT COUNT THAT VALUE’
Then- This statement is used to execute particular value or display particular value when the condition in WHEN statement is satisfied.
Example
CASE b
WHEN 3
THEN ‘three ORANGE’
WHEN 4
THEN ‘four ORANGES’
ELSE
‘CANNOT COUNT THAT VALUE’.
Else- When the when condition is not satisfied the process leads to another option, that is defined as else statement.
Example
WHEN 5
THEN ‘FIVE ORANGES’
ELSE
‘CANNOT COUNT THAT VALUE’.
End- It is used to terminate the program which leads the system to stop the execution.
Example
CASE x
WHEN 1
THEN ‘COUNT 1’
WHEN 2
THEN ‘COUNT 2’
ELSE ‘ERROR’
END