AND Operator

SQL · Filtering Rows

Theory

AND combines two conditions and is TRUE only when both are TRUE. WHERE dept = 'IT' AND salary > 80000 keeps employees who are in IT and also earn more than ₹80,000; a row failing either test is removed. You can chain any number of conditions with AND, and each one narrows the result further.

With NULLs, AND follows three-valued logic: FALSE AND anything is FALSE, TRUE AND UNKNOWN is UNKNOWN, so the row is dropped. AND has higher precedence than OR, which means a OR b AND c is read as a OR (b AND c). Use parentheses whenever you mix the two. Many engines can stop evaluating once one side is FALSE, but the order is not guaranteed, so do not rely on short-circuiting to avoid errors.

Why we use it

Real questions usually have several requirements at once: a department and a salary range, a city and a date. AND lets you state all of them in one filter so only rows meeting every rule survive.

When to use it

Use AND when every condition must hold. If any one condition is enough, use OR or IN. When mixing AND with OR, wrap the OR part in parentheses so the logic is explicit.

How it works

  1. Read a row
  2. Evaluate the first condition
  3. Is it TRUE? Yes: Evaluate the next condition. No: Row fails: discard it.
  4. Are all conditions TRUE? Yes: Keep the row. No: Discard the row.
  5. Move to the next row

Syntax

SELECT columns FROM table
WHERE cond1 AND cond2;

Example

SELECT * FROM employees WHERE department = 'IT' AND salary > 50000;

Key points

SQL topics

Introduction to SQL

Querying Data

Sorting Rows

Limiting Rows

Filtering Rows

Joining Multiple Tables

Grouping Rows

SET Operators

Working with Tables

Modifying Data

Views & Triggers

Conditional Expressions

SQL Subqueries

Aggregate Functions

Window Functions

String Functions

Date Functions

Math Functions

Extra Concepts

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Master SQL from Zero to Pro

All SQL topics in one place. Click any topic in the sidebar — content opens right here without leaving the page.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice SQL Online Solve 150 SQL interview problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

SQL  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs against a real sample database
{{ liveError }}
{{ col }}
{{ cell }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic