SQL (Structured Query Language) is a programming language that is used to define, manipulate, and control the data stored in a database management system (DBMS). SQL includes a set of operators that are used to perform various operations on the data, such as comparisons, calculations, and logical tests.
The following is a list of the most common SQL operators, along with examples of how they can be used in a SQL query:
- Arithmetic operators: Arithmetic operators are used to perform mathematical calculations on the data. The following are the arithmetic operators in SQL:
-
- (addition) – Used to add two or more numbers. For example:
SELECT 2 + 3 + 5;
-
- (subtraction) – Used to subtract one number from another. For example:
SELECT 10 - 3;
-
- (multiplication) – Used to multiply two or more numbers. For example:
SELECT 2 * 3 * 5;
- / (division) – Used to divide one number by another. For example:
SELECT 10 / 2;
- % (modulus) – Used to find the remainder of a division. For example:
SELECT 10 % 3;
- Comparison operators: Comparison operators are used to compare two values and determine if they are equal, greater than, or less than each other. The following are the comparison operators in SQL:
- = (equal to) – Used to test if two values are equal. For example:
SELECT * FROM customers WHERE age = 30;
- <> (not equal to) – Used to test if two values are not equal. For example:
SELECT * FROM customers WHERE age <> 30;
-
(greater than) – Used to test if one value is greater than another. For example:
SELECT * FROM customers WHERE age > 30;