SQL has various operators that can be used within a SELECT statement to perform different operations. Here are some common operators:
1. Arithmetic Operators:
Addition (+)
Subtraction (-)
Multiplication (*)
Division (/)
Modulus (%)
Example:
SELECT column1 + column2 AS sum_result
FROM table_name;
2. Comparison Operators:
Equal to (=)
Not equal to (!= or <>)
Greater than (>)
Less than (<)
Greater than or equal to (>=)
Less than or equal to (<=)
Example:
SELECT * FROM table_name
WHERE column1 > 100;
3. Logical Operators:
AND
OR
NOT
Example:
SELECT * FROM table_name
WHERE column1 > 100 AND column2 < 500;
4.Concatenation Operator:
Concatenates two or more strings.
Example:
SELECT CONCAT(first_name, ' ', last_name) AS full_name
FROM employees;
5. LIKE Operator:
Used in a WHERE clause to search for a specified pattern in a column.
Example:
SELECT * FROM employees
WHERE last_name LIKE 'Smith%';
6. IN Operator:
Checks if a value matches any value in a list.
Example:
SELECT * FROM employees
WHERE department IN ('HR', 'Finance', 'IT');
7. BETWEEN Operator:
Checks if a value is within a specified range.
Example:
SELECT * FROM employees
WHERE salary BETWEEN 50000 AND 80000;
8. IS NULL Operator:
Check if a column contains NULL values.
Example:
SELECT * FROM employees
WHERE email IS NULL;
9. IS NOT NULL Operator:
Checks if a column does not contain NULL values.
Example:
SELECT * FROM employees
WHERE email IS NOT NULL;
10. DISTINCT Operator:
Removes duplicate rows from the result set.
Example:
SELECT DISTINCT department FROM employees;
11.ORDER BY Operator:
Sorts the result set in ascending or descending order.
Example:
SELECT * FROM employees
ORDER BY salary DESC;