SQL_Operator_7
SQL_Operator_7
Opera Descript
Example
tor ion
+ Addition SELECT *, Cost + 5 as New_Cost FROM Products;
Subtracti
– SELECT *, Price - Cost as Proft FROM Products;
on
Multiplica
* SELECT *, Price * Quantity as Revenue FROM Products;
tion
/ Division SELECT *, Cost / Price as Cost_Price_Ratio FROM Products;
% Modulus SELECT *, Price % Cost as Price_Cost_Modulus FROM Products;
Opera Descripti
Example
tor on
= Equal to SELECT * FROM Products WHERE Price = 50;
<> Not equal
SELECT * FROM Products WHERE Price <> 50;
or != to
Greater
> SELECT * FROM Products WHERE Price > 50;
than
< Less than SELECT * FROM Products WHERE Price < 50;
Greater
>= than or SELECT * FROM Products WHERE Price >= 50;
equal to
Less than
<= or equal SELECT * FROM Products WHERE Price <= 50;
to
Opera Descripti
Example
tor on
True if all
AND condition SELECT * FROM Products WHERE Price > 20 AND Quantity < 10;
s are true
OR True if at SELECT * FROM Products WHERE Price < 20 OR Quantity > 10;
Opera Descript
Example
tor ion
least one
condition
is true
True if
the
NOT SELECT * FROM Products WHERE NOT Price = 30;
condition
is false
True if
the value
IN SELECT * FROM Products WHERE ProductID IN (1,2,3);
is in the
list
True if
BETW the value
SELECT * FROM Products WHERE Price BETWEEN 20 AND 30;
EEN is within
the range
True if
the value
LIKE matches SELECT * FROM Products WHERE ProductName LIKE 'A%';
the
pattern
True if
the
subquery SELECT * FROM Products WHERE
EXIST
returns EXISTS (SELECT ProductID FROM Inventory WHERE Products.Pro
S
at least ductID = Inventory.ProductID);
one
record