T-SQL - OR Operator
The T-SQL (Transact-SQL) OR Operator is used to combine multiple conditions in a WHERE clause of T-SQL statement. It displays a record if any the conditions separated by OR operator is true.
Syntax
The syntax for using OR operator in T-SQL (Transact-SQL) is given below:
SELECT column1, column2, column3, ... FROM table_name WHERE condition1 OR condition2 OR condtion3 ....;
Example:
Consider a database containing 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 all records of the Employee table where Salary is greater than 2800 or Age is less than 25, the query is given below.
SELECT * FROM Employee WHERE Salary > 2800 OR Age < 25;
This will produce the result as shown below:
EmpID Name City Age Salary 1 John London 25 3000 2 Marry New York 24 2750 4 Kim Amsterdam 30 3100 5 Ramesh New Delhi 28 3000
❮ T-SQL - Operators