</>
Skip to content
MySQL lessons (16/48)

MySQL — Where

Basic WHERE

SELECT * FROM users WHERE age > 18;

Comparison Operators

-- Equal
SELECT * FROM users WHERE name = 'John';

-- Not equal
SELECT * FROM users WHERE name != 'John';

-- Greater than
SELECT * FROM users WHERE age > 18;

-- Less than
SELECT * FROM users WHERE age < 30;

-- Greater than or equal
SELECT * FROM users WHERE age >= 18;

-- Less than or equal
SELECT * FROM users WHERE age <= 30;

Logical Operators

-- AND
SELECT * FROM users WHERE age > 18 AND age < 30;

-- OR
SELECT * FROM users WHERE age < 18 OR age > 60;

-- NOT
SELECT * FROM users WHERE NOT age < 18;

WHERE Examples

-- LIKE operator
SELECT * FROM users WHERE name LIKE 'John%';
SELECT * FROM users WHERE email LIKE '%@gmail.com';

-- IN operator
SELECT * FROM users WHERE age IN (18, 25, 30);

-- BETWEEN operator
SELECT * FROM users WHERE age BETWEEN 18 AND 30;

-- IS NULL
SELECT * FROM users WHERE age IS NULL;

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

Mini Practice

Write MySQL code that:

  1. Uses comparison operators
  2. Uses logical operators
  3. Uses LIKE operator
  4. Uses IN and BETWEEN

Up Next

Next: Learn about Updating Data.

Related Topics

Frequently Asked Questions about Where

What is Where in MySQL?

Where is a fundamental concept in MySQL. 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 MySQL?

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