Conditional Expressions: The AND Operator
Summary:
The AND
operator is used for joining multiple conditional expressions. The basic syntax for an AND
operator joining two different conditional expressions is:
conditional_expression_1 AND conditional_expression_2
This is very useful in the SELECT
statements when we want to conditionally select data. For example, the most common usage is when defining ranges.
Let's consider a situation where we want to fetch all of the employees that earn more than $50000 and less than $60000. We can do so by joining the following two expressions:
salary > 50000
;salary < 60000
.
So the compound expression will look like: salary > 50000 AND salary < 60000
.
Putting it inside a select statement will result into the following query:
SELECT *
FROM employees
WHERE salary > 50000 AND salary < 60000;
It is important to note that we can chain together more than two conditions using the AND
operator:
conditional_expression_1 AND conditional_expression_2 AND conditional_expression_3 β¦
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 1.72
Conditional Expressions: The AND Operator
Swipe to show menu
Summary:
The AND
operator is used for joining multiple conditional expressions. The basic syntax for an AND
operator joining two different conditional expressions is:
conditional_expression_1 AND conditional_expression_2
This is very useful in the SELECT
statements when we want to conditionally select data. For example, the most common usage is when defining ranges.
Let's consider a situation where we want to fetch all of the employees that earn more than $50000 and less than $60000. We can do so by joining the following two expressions:
salary > 50000
;salary < 60000
.
So the compound expression will look like: salary > 50000 AND salary < 60000
.
Putting it inside a select statement will result into the following query:
SELECT *
FROM employees
WHERE salary > 50000 AND salary < 60000;
It is important to note that we can chain together more than two conditions using the AND
operator:
conditional_expression_1 AND conditional_expression_2 AND conditional_expression_3 β¦
Thanks for your feedback!