Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

SQL operator


May 16, 2021 SQL


Table of contents


SQL operator


Operators are characters in the WHERE clause that preserve words or are primarily used for SQL statements and are used to perform actions such as comparison and arithmetic operations. These operators are used to specify the conditions in the SQL statement and to be used as a verse for multiple conditions in the statement.

There are several common operators:

  • Arithmetic operator
  • Comparison operator
  • The logical operator
  • The negative condition operator

SQL arithmetic operator


Suppose the value of variable a is: 10, the value of variable b is: 20, and the following are the results of each operator execution:

Operator Describe Example

+

addition, performing addition operations.

a plus b gets 30

-

Subtract, perform subtract operations.

a - b gets -10

*

Multiplication, performing multiplication.

a :b gets 200

/

Divide the left operans by the right.

b / a gets 2

%

Divide the left operant by the right and return the remaining number.

b % a gets 0


SQL comparison operator


Suppose the value of variable a is: 10, the value of variable b is: 20, and the following are the results of each operator execution:

Operator Describe Example
= Check that the values of the two operasts are equal and, if so, true.
(a = b) is false.
!= Check that the values of the two operasts are equal, and that the condition is true if the values are not equal.
(a != b) is true.
<> Check that the values of the two operasts are equal, and that the condition is true if the values are not equal. (a <> b) is true.
> Check that the value of the left operance is greater than the value of the right operast?
(a > b) is false.
< Check that the value of the left operance is less than the value of the right operance, and if so, the condition is true. (a < b) is true.
>= Check that the value of the left operance is greater than or equal to the value of the right operans, and if so, the condition is true. (a >= b) is false
<= Check that the value of the left operanzo is less than or equal to the value of the right operans, and if so, the condition is true. (a <= b) is true.
!< Check that the value of the left operance is not less than the value of the right operans, and if so, the condition becomes true. (a !< b) is false.
!> Check that the value of the left operance is not greater than the value of the right operast? (a !> b) is true.

SQL logical operator:


This is a list of all logical operators in SQL.

Operator Describe
ALL The ALL operator is used to compare values to all values in another value set.
AND The AND operator allows multiple conditions to be specified in the WHERE clause of the SQL statement.
ANY The ANY operator is used to compare values to any applicable values in the list based on conditions.
BETWEEN The BETWEEN operator is used to search for values within a given minimum and maximum value.
EXISTS The EXISTS operator is used to search for rows in the specified table that meet certain criteria.
IN The IN operator is used to compare values to a list of text values that have been specified.
LIKE The LIKE operator is used to compare values to similar values using wildcard operators.
NOT The NOT operator reverses the meaning of the logical operator that uses it. F or example: NOT EXISTS, NOT BETWEEN, NOT IN, etc., this is a negative operator.
OR The OR operator is used to combine multiple conditions in the WHERE clause of an SQL statement.
IS NULL The IS NULL operator is used to compare values to NULL values.
UNIQUE The UNIQUE operator searches for the uniqueness (no duplicates) of each row of the specified table.


Chapter test


Now, take a look at how well you know the SQL operator with the following topics!

SQL IN, NOT IN Operator: In this section of the quiz, you'll practice using SQL's IN operator and the NOT IN operator

Click here to test

SQL LIKE Operator: In this section of the quiz, you'll practice using SQL's LIKE operator

Click here to test

Note: The above tests are paid and premium VIP is free of charge

For more questions, please refer to: SQL Quiz Library