Curriculum
In this tutorial, you’ll learn how to use AND operator in the T-SQL query in SQL Server along with some examples.
The AND operator in SQL Server is one of the logical operator that is mainly used to test for two or more conditions. It mainly combines two or more Boolean expressions and returns true only if all the expressions evaluate to TRUE in the query.
WHERE expression1 AND expression2 ... AND expressionn;
It is important to note that the AND operator is mainly used to evaluate two or more expressions and all of the conditions must return true for the record to be included in the result set.
Also, when there are more than one logical operator used in an expression, the AND operator always takes the precedence and evaluates first. The precedence can be changed by using the parenthesis.
The below SQL query find all the Person records where the title is Mr. and EmailPromotion is set.
SELECT * FROM [Person].[Person] WHERE Title = 'Mr.' AND EmailPromotion = 1
The below query returns all the Person records that meets all the conditions as specified below
SELECT * FROM [Person].[Person] WHERE Title = 'Mr.' AND EmailPromotion = 1 AND PersonType = 'SP'