(Equal) = Operator
The (Equal) = operator is used with Where Clause in SQL. For Example consider the student table given below,
ROLL_NO | NAME | ADDRESS | PHONE | Age |
---|---|---|---|---|
1 | Ram | Delhi | xxxxxxxxxx | 18 |
2 | RAMESH | GURGAON | xxxxxxxxxx | 18 |
3 | SUJIT | ROHTAK | xxxxxxxxxx | 20 |
4 | SURESH | Delhi | xxxxxxxxxx | 18 |
3 | SUJIT | ROHTAK | xxxxxxxxxx | 20 |
2 | RAMESH | GURGAON | xxxxxxxxxx | 18 |
Query :
To fetch record of students with address as Delhi or ROHTAK. The SQL query using = operator would be,
SELECT *
FROM Student
WHERE ADDRESS='Delhi' OR ADDRESS='ROHTAK';
Output :
ROLL_NO | NAME | ADDRESS | PHONE | Age |
---|---|---|---|---|
1 | Ram | Delhi | xxxxxxxxxx | 18 |
3 | SUJIT | ROHTAK | xxxxxxxxxx | 20 |
4 | SURESH | Delhi | xxxxxxxxxx | 18 |
3 | SUJIT | ROHTAK | xxxxxxxxxx | 20 |
Difference between (Equal) = and IN operator in SQL
Equal (=) and IN operators are both comparison operators in SQL, the only difference between = and IN operator is that ‘=’ operator compares two values, but IN operator compares a value against set of values.
Here, we will learn the difference between the SQL ‘=’ and IN operator by understanding each of them.
Contact Us