OPERATORS
COMPARISON OPERATORS
SQL
Ppt Template by: https://poweredtemplate.com/04066/0/index.html
Comparison Operators
• Compare expressions and return one
of three values: TRUE, FALSE, or
Unknown. ?
Null or absence of data in a
field, not a zero or a blank
nothing is in that field
Ppt Template by: https://poweredtemplate.com/04066/0/index.html
Comparison Operators
• SELECT * FROM PRICE WHERE
WHOLESALE IS NULL;
ORANGES is the only item whose value for WHOLESALE is
NULL or does not contain a value. What if you use the equal sign
(=) instead?
Ppt Template by: https://poweredtemplate.com/04066/0/index.html
Comparison Operators
• SELECT * FROM PRICE WHERE
WHOLESALE = NULL;
You didn't find anything because the comparison WHOLESALE = NULL returned a
FALSE (the result was unknown). It would be more appropriate to use an IS NULL
instead of =, changing the WHERE statement to WHERE WHOLESALE IS NULL.
In this case you would get all the rows where a NULL existed.
Ppt Template by: https://poweredtemplate.com/04066/0/index.html
Comparison Operators: Equal ( = )
• In the WHERE clause, the equal sign is
the most commonly used comparison
operator.
• Used alone, the equal sign is a very
convenient way of selecting one value
out of many.
Ppt Template by: https://poweredtemplate.com/04066/0/index.html
Comparison Operators: Equal ( = )
INPUT
SELECT * FROM FRIENDS WHERE FIRSTNAME = 'BUD';
SELECT * FROM FRIENDS WHERE FIRSTNAME = 'AL';
NOTE: Here you see that = can pull in multiple records
Ppt Template by: https://poweredtemplate.com/04066/0/index.html
Greater Than (>) and
Greater than or Equal (>=)
Try this:
SELECT * FROM FRIENDS WHERE AREACODE > 82;
SELECT * FROM FRIENDS WHERE AREACODE >= 82;
Ppt Template by: https://poweredtemplate.com/04066/0/index.html
Less Than (<) and
Less Than or Equal To (<=)
Try this:
SELECT * FROM FRIENDS WHERE STATE < 'LA';
SELECT * FROM FRIENDS WHERE STATE <= 'LA';
Ppt Template by: https://poweredtemplate.com/04066/0/index.html
Inequalities (< > or !=)
When you need to find everything except for certain
data, use the inequality symbol (either < > or !=,
depending on your SQL implementation).
Ppt Template by: https://poweredtemplate.com/04066/0/index.html
Inequalities (< > or !=)
Ex. Find everyone who is not AL from table
FRIENDS.
SELECT * FROM FRIENDS WHERE FIRSTNAME <> 'AL';
Ppt Template by: https://poweredtemplate.com/04066/0/index.html