Menu
Coddy logo textTech

Conditions Basics

Part of the Fundamentals section of Coddy's SQL journey — lesson 5 of 72.

Sometimes we would like to fetch records that meet a certain condition.

For example

  • fetch all of the records that have the family name "Aothly" 
  • fetch all of the records that the amount is bigger than 5
  • fetch all of the records with the country "Mexico"

To add conditions we can use the WHERE keyword

For example here is a sales table:

coinamount
AGK13
GOL21
KLA15
AGK18

To fetch all of the records with the coin "AGK" we will write:

SELECT * FROM sales
WHERE coin = 'AGK'

To fetch all of the records with amount smaller or equal to 20 we will write:

SELECT * FROM sales
WHERE amount <= 20
challenge icon

Challenge

Easy

Available tables and columns:

  • <strong>events</strong>: <strong>event_id</strong>, <strong>people</strong>

Fetch all of the event_ids where people is less than 14 people

Cheat sheet

Use the WHERE keyword to add conditions to your SQL queries:

SELECT * FROM table_name
WHERE column_name = 'value'

For numeric comparisons:

SELECT * FROM table_name
WHERE column_name <= 20

Common comparison operators: =, <, >, <=, >=

Try it yourself

SELECT event_id FROM events
-- Write your code below
WHERE
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals