SQLancer
LESSON 2

SQL (Core) - Queries with constraints (Pt. 1)

Progress: 0%

Queries with constraints (Pt. 1)

When working with databases containing millions of rows, returning the entire table is inefficient. In order to filter results down to specific target records, we use the WHERE clause.

Select Query with Constraints Syntax

SELECT column, another_column FROM mytable WHERE condition AND/OR another_condition;

The WHERE clause is evaluated for each row in the table. If the condition resolves to TRUE, the row is included in the output; if FALSE, it is discarded.

Operator Condition SQL Example
=, !=, <, <=, >, >= Standard numerical comparison year >= 2000
BETWEEN ... AND ... Number is within inclusive range year BETWEEN 2000 AND 2010
NOT BETWEEN ... AND ... Number is outside inclusive range year NOT BETWEEN 2000 AND 2010
IN (...) Number matches any item in a discrete list id IN (1, 3, 5)
NOT IN (...) Number matches no items in a discrete list id NOT IN (2, 4, 6)

Combining Logical Operators (AND / OR / NOT)

You can combine multiple criteria using AND (both conditions must be true) and OR (at least one condition must be true). Always use parentheses (...) when mixing AND and OR to explicitly dictate operator precedence.

🗄️ Schema Explorer SELECTABLE

movies
|

🎯 Exercises Checklist:

1. Find the movie with a row id of 6
2. Find the movies released in the years between 2000 and 2010
3. Find the movies not released in the years between 2000 and 2010
4. Find the first 5 Pixar movies and their release year
⚡ Practice Console

Data Output

No results. Run query to fetch data.

Current Task Target

5 rows