SQL - Equal to (=) Operator
The SQL = (equal to) operator checks if the value of left operand is equal to the value of right operand and returns true if the condition is true, false otherwise.
Note: The = operator is also used to assign value (for example assigning values with UPDATE statement).
Syntax
The syntax for using equal to operator is given below:
expression = expression
Parameters
expression |
Any valid expression. Both expressions must have implicitly convertible data types. |
Example 1:
The example below shows the usage of equal to operator:
SELECT 10 = 10; Result: 1 SELECT 10.0 = 10; Result: 1 SELECT 10 = 20; Result: 0 SELECT 'abc' = 'abc'; Result: 1 SELECT 'abc' = 'xyz'; Result: 0
Example 2:
Consider a database table called Employee with the following records:
EmpID | Name | City | Age | Salary |
---|---|---|---|---|
1 | John | London | 25 | 3000 |
2 | Marry | New York | 24 | 2750 |
3 | Jo | Paris | 27 | 2800 |
4 | Kim | Amsterdam | 30 | 3100 |
5 | Ramesh | New Delhi | 28 | 3000 |
6 | Huang | Beijing | 28 | 2800 |
To select records of table where Age of the person is equal to 28, the query is given below.
SELECT * FROM Employee WHERE Age = 28;
The query will produce following result:
EmpID | Name | City | Age | Salary |
---|---|---|---|---|
5 | Ramesh | New Delhi | 28 | 3000 |
6 | Huang | Beijing | 28 | 2800 |
❮ SQL Operators