SQL AND & OR Operators

Published on by LakshmiSaahul,Dhana Royal

SQL AND & OR Operators

SQL AND operator is used to filter the records by combining two boolean expressions and returns true when both boolean expressions are true whereas SQL OR operator returns true value when either the first condition or the second condition is true or when both conditions are true.

SQL AND Operator

As you can see in below query, AND operator evaluates FirstName and Country columns and when both conditions are met then it returns the row.

SELECT *FROM Student
WHERE FirstName = 'Gail' AND Country = 'Germany'

SQL OR Operator

As you can see from below example, we are using OR operator and evaluating the sameconditions which we used in AND operator. Here OR operator returns all records where conditionsfor either column values FirstName OR Country are satisfied.

SELECT *FROM Student
WHERE FirstName = 'Gail' OR Country = 'Germany'

Combine AND & OR Operator

You can also combine both AND & OR operators to evaluate the conditions. When more than one logical operators are used in a query then AND operator is evaluated before OR operator.

SELECT *FROM Student
WHERE FirstName = 'Roberto' AND (RollNumber = 1005 OR Country = 'India')
Advertising
To be informed of the latest articles, subscribe:
Comment on this post