🗄️ SQL examples

WHERE Examples in SQL

Filter rows with conditions. This page gives you the syntax, five practical examples, common mistakes, and copy-ready SQL you can adapt.

Updated 2026-06-125 practical examplesCopy-ready SQL

What WHERE does

Filter rows with conditions. SQL syntax can vary by database, but the pattern below is a useful starting point for reports and analysis.

Syntax or pattern

SELECT * FROM table_name WHERE condition;
✍️

5 practical examples

1

Filter active customers

Return only customers marked active.

SELECT customer_id, email FROM customers WHERE status = 'Active';

WHERE limits rows before they appear in the result.

2

Filter orders after a date

Show recent orders only.

SELECT order_id, order_date, total_amount FROM orders WHERE order_date >= DATE '2026-01-01';

Date filters are common in monthly and yearly reports.

3

Filter high-value orders

Find orders above a threshold.

SELECT order_id, customer_id, total_amount FROM orders WHERE total_amount >= 500;

Use numeric filters to focus on important transactions.

4

Filter by multiple conditions

Find online orders in a region.

SELECT * FROM orders WHERE channel = 'Online' AND region = 'West';

AND requires both conditions to be true.

5

Exclude cancelled rows

Remove rows with a status you do not want.

SELECT * FROM orders WHERE status <> 'Cancelled';

This keeps cancelled activity out of operational summaries.

Common mistakes to avoid

  • Forgetting that SQL dialects vary across PostgreSQL, SQL Server, MySQL, BigQuery and SQLite.
  • Using SELECT * in production reports when only a few columns are needed.
  • Not checking join keys, duplicate rows or NULL values before trusting results.

FAQ

Will this SQL work in every database?

The idea is portable, but function names and date syntax may vary. Check your database dialect if a function is not recognized.

Should I use this in a report query?

Yes, if the pattern matches the business question and you have checked filters, joins and row counts.

Why does my result have too many rows?

The most common reasons are duplicate join keys, missing filters or grouping at the wrong level of detail.

💡 Useful resources

Here are some ideas for you

Optional resources that may help if you are learning SQL, building reports, writing queries or improving your data workflow.

  • 📘
    SQL books for beginners

    Practice query patterns with structured examples and exercises.

    See ideas
  • 🧱
    Database design books

    Understand tables, keys, relationships and why joins behave the way they do.

    See ideas
  • ⌨️
    Mechanical keyboards

    Useful if you write queries, code and documentation for long work sessions.

    See ideas
  • 🖥️
    External monitors

    View query editor, result grid and documentation side by side.

    See ideas
  • 📒
    Developer notebooks

    Sketch table relationships, query logic and report ideas before coding.

    See ideas
  • 💡
    Desk lamps

    Keep your workspace comfortable while studying or debugging queries.

    See ideas

Some links in this section may be affiliate links. Choose only what is useful for your own work.