How to use OR With Other Logical Operator In SQL
SELECT * FROM CoursesActive
WHERE courseId = 1001
OR courseId =1002
OR courseId = 1003
OR courseId = 1004
AND courseCost>1500
The Result Looks Like:
Explanation : In this query there are combination of there OR and one AND operator with there conditions which are courseId = 1001 or courseId =1002 or courseId = 1003 or courseId = 1004 and courseCost>1500 the AND operator has the higher precedence so that will be evaluated first there is 1 row with courseId = 1004 , courseCost>1500 and remaining three rows with the remaining three conditions.
SQL Server OR Operator
Logical operators are used for combining multiple boolean expressions which are a combination of results of multiple conditions which are formed by the comparators. Some of the logical operators are AND, OR, EXISTS, IN, LIKE, BETWEEN, etc, Logical operators are very frequently used and are very handy for testing multiple conditions. The logical operator OR is used for combining multiple boolean expressions and it returns true only when any one of the conditions is true. It is used primarily with WHERE, CASE, and HAVING clauses by specifying multiple boolean expressions that return any one of the following values True, or False.