🚀 New batches open: Advanced Excel • Power BI • SQL • AI for Analytics — Book a free demo
Home / SQL Tutorial / Day 3

Day 3 — Combining conditions

Real questions have more than one condition. Today you learn to stack them — and where the brackets go.

AND — both must be true

OR — either can be true

Mixing AND with OR — use brackets

AND is evaluated before OR, exactly like multiplication before addition. That is a very easy way to get a wrong answer that looks right.

These two are not the same WHERE City = 'Noida' OR City = 'Delhi' AND Segment = 'Retail'
reads as: Noida (anything), OR Delhi that is Retail.
Put brackets where you mean them.

Run both of these and compare the row counts. Same words, different brackets, different answer.

The first returns 3 rows — it lets in Singh & Co, a Noida wholesaler, because AND bound tighter than OR. The second returns 2, which is almost certainly what was meant.

IN — a tidy list

IN is shorthand for lots of ORs on the same column.

BETWEEN — a range, both ends included

BETWEEN 30000 AND 50000 includes both 30000 and 50000.

LIKE — pattern matching on text

  • % stands for any number of characters
  • _ stands for exactly one character

Contains, rather than starts with:

NOT — flip any condition

Try these yourself

  1. Orders that are Pending AND above 20000.
  2. Customers in Haryana OR Maharashtra.
  3. Products priced between 1000 and 10000.
  4. Employees whose Name starts with A.
  5. Orders NOT handled by Amit.

Want this taught properly?

This tutorial covers the basics. Our SQL course in Noida takes you through window functions, CTEs and stored procedures on a real database, with projects and mentor support.

See the SQL course →