SQL Operators

SQL Arithmetic Operators

Operator Description Example
+ Addition SELECT 5 + 3; -- Output: 8
- Subtraction SELECT 5 - 3; -- Output: 2
* Multiplication SELECT 5 * 3; -- Output: 15
/ Division SELECT 6 / 3; -- Output: 2
% Modulus (Remainder) SELECT 5 % 2; -- Output: 1

SQL Comparison Operators

Operator Description Example
= Equal to SELECT 5 = 3; -- Output: 0
<> or != Not equal to SELECT 5 != 3; -- Output: 1
< Less than SELECT 5 < 3; -- Output: 0
<= Less than or equal to SELECT 5 <= 3; -- Output: 0
!< Not less thanto SELECT 5 !< 3; -- Output: 1
> Greater than SELECT 5 > 3; -- Output: 1
>= Greater than or equal to SELECT 5 >= 3; -- Output: 1
!> Not greater than SELECT 5 !> 3; -- Output: 0

Operators !<, !> are not supported by every DB!

Operator Description Example
ALL Returns true if all subquery values meet the condition SELECT * FROM employees
WHERE salary > ALL (SELECT salary FROM managers);
AND Returns true if both conditions are true SELECT * FROM customers
WHERE age > 25 AND city = 'New York';
ANY Returns true if any subquery values meet the condition SELECT * FROM employees
WHERE salary > ANY (SELECT salary FROM managers);
BETWEEN Returns true if a value is within a range of values SELECT * FROM products
WHERE price BETWEEN 10 AND 20;
EXISTS Returns true if a subquery contains any rows SELECT * FROM customers
WHERE EXISTS (SELECT * FROM orders WHERE orders.customer_id = customers.id);
IN Returns true if a value matches any value in a list SELECT * FROM customers
WHERE city IN ('New York', 'Los Angeles');
LIKE Returns true if a value matches a pattern SELECT * FROM customers
WHERE name LIKE 'J%';
NOT Reverses the result of a condition SELECT * FROM customers
WHERE NOT city = 'New York';
OR Returns true if either condition is true SELECT * FROM customers
WHERE age > 25 OR city = 'New York';
IS NULL Returns true if a value is null SELECT * FROM customers
WHERE phone IS NULL;
UNIQUE Returns true if all values in a column are unique SELECT UNIQUE product_name FROM orders;

Комментарии

Популярные сообщения из этого блога

MapBox-compatible file formats and limitations