</>
Skip to content
PostgreSQL lessons (15/38)

PostgreSQL — Where

Basic WHERE

SELECT * FROM users WHERE id = 1;
SELECT * FROM users WHERE name = 'John';

Comparison Operators

OperatorDescription
=Equal
!= or <>Not equal
>Greater than
<Less than
>=Greater or equal
<=Less or equal

Logical Operators

-- AND
SELECT * FROM users WHERE age > 18 AND active = true;

-- OR
SELECT * FROM users WHERE country = 'USA' OR country = 'UK';

-- NOT
SELECT * FROM users WHERE NOT active;

IN

SELECT * FROM users WHERE country IN ('USA', 'UK', 'Canada');

BETWEEN

SELECT * FROM users WHERE age BETWEEN 18 AND 30;

LIKE

SELECT * FROM users WHERE name LIKE 'J%';    -- Starts with J
SELECT * FROM users WHERE name LIKE '%son';  -- Ends with son
SELECT * FROM users WHERE name LIKE '%oh%';  -- Contains oh

IS NULL

SELECT * FROM users WHERE email IS NULL;
SELECT * FROM users WHERE email IS NOT NULL;

Mini Practice

  1. Use comparison operators
  2. Use logical operators
  3. Use IN and BETWEEN
  4. Use LIKE pattern matching

Up Next

Continue with Update — updating data.

Related Topics

Frequently Asked Questions about Where

What is Where in PostgreSQL?

Where is a fundamental concept in PostgreSQL. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Where?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Where.

Why is Where important in PostgreSQL?

Where is essential for PostgreSQL development. Understanding this concept will help you write better code and solve real-world problems more effectively.