In the previous article, you learned about the basic SQL statement structure, the types of data in SQL.In this article, we will learn about operators inSQL.

What are the operators in SQL?

Operator in SQL

Operator in SQL

Operators are reserved words or characters that are used primarily in the WHERE clause ofthe SQL statementto perform operations, such as comparing arithmetic operations.These operators are used to specify conditions in an SQL statement and serve as the delivery of many conditions in a statement.

Operators in SQL include:

  • Arithmetic operator
  • Comparison operator
  • Logical operators
  • Operators are used to negate conditions

Arithmetic operator in SQL

Assuming variable a saves value 10, variable b saves value 20, then

Operator Describe For example
+ (Plus) Add the values on both sides of the operator (addition). a + b gives 30 results
– (minus) Get the left operand minus the right operand (subtraction). a – b gives the result of -10
* (Human) Multiply the value of two operands on the two operators (multiplication). a * b gives the result of 200
/ (Share) Split the left operand for the right operand (division). b / a results in 2
% (Split Balance) Break the left operand for the right operand and then subtract the remainder. b% a results in 0

Comparison operators in SQL

We still use the suppose, a = 10, b = 20.

Operator Describe For example
= Check that the value of the two operands on the equals sign is equal, if true, the condition is true. (a = b) not true.
= Check if the values of the two operands are equal, otherwise the condition is true. (!! b) is true.
<> Verify that the values of the two operands are equal, otherwise the condition is true. (a <> b) is true.
> Check that the value of the left operand is greater than the value of the operand on the right, if true then the condition is true. (a> b) not true.
< Verify that the value of the left operand is less than the value of the operand on the right, if true then the condition is true. (<b) is true.
> = Verify that the value of the left operand is greater than or equal to the value of the operand on the right, if true then the condition is true. (a> = b) is not true.
<= Verify that the value of the left operand is less than or equal to the value of the operand on the right, if true then the condition is true. (a <= b) is true.
< Verify that the value of the left operand is not less than the value of the operand on the right, if true then the condition is true. (!! b) is false.
> Verify that the value of the left operand is no greater than the value of the operand on the right, if true then the condition is true. (!! b) is true.

Logical operators in SQL

This is a list of logical operators in SQL.

Operator Describe
ALL The ALL operator is used to compare a value with all values in a different set of values.
AND The AND operator allows multiple conditions to coexist in the WHERE clause of the SQL statement.
ANY The ANY operator is used to compare a value with any appropriate value in the list depending on the condition.
BETWEEN The BETWEEN operator is used to search for values in a set of values, with the smallest value and the largest value given.
EXISTS The EXISTS operator is used to find the presence of a row in the table that satisfies the specified condition.
PRINT The IN operator is used to compare values with predefined string value lists.
LIKE The LIKE operator is used to compare values with similar values, using Wildcard operators.
NOT The NOT operator reverses the meaning of the logical operator that is used.For example: NOT EXISTS, NOT BETWEEN, NOT IN, … This is a negative operator.
OR The OR operator is often used to join multiple conditions in the WHERE clause of an SQL statement.
IS NULL The NULL operator is used to compare a value with a NULL value.
UNIQUE The UNIQUE operator searches uniquely for every row in the table (no duplicates).

Here are some of the most basic SQL operands, and in the next article we’ll look at SQL expressions, do not miss it.

Previous article:Data types in SQL

Reference: tutorialspoint.com

Leave a Comment

Close