WHERE clause with an equal = operator

In this exercise we'll query the orders table and return just the rows that equal the employee_id of 8.

SELECT order_id,
customer_id,
employee_id,
order_date
FROM orders
WHERE employee_id=8;
Run in terminal

This query should return 104 rows.

WHERE clause with an AND operator

In this exercise we'll query the orders table and return just the rows that have an employee_id of 8 and a customer_id equal to "FOLKO".

SELECT order_id,
customer_id,
employee_id,
order_date
FROM orders
WHERE employee_id=8
AND customer_id= 'FOLKO';
Run in terminal

This query should return 6 rows.

WHERE clause with an OR operator

In this exercise we'll query the orders table and return just the rows that have an employee_id of 2 or 1.

SELECT order_id,
customer_id,
employee_id,
order_date
FROM orders
WHERE employee_id=2
OR employee_id=1;
Run in terminal

This query should return 219 rows.

WHERE clause with an IN operator

In this exercise we'll query the order_ details table and return just the rows with an order_id of 10360 or 10368.

SELECT *
FROM order_details
WHERE order_id IN (10360,
10368);
Run in terminal

This query should return 9 rows.

WHERE clause with a LIKE operator

In this exercise we'll query the customers table and return just the rows that have a company_name that starts with the letter "F".

SELECT customer_id,
company_name,
contact_name,
city
FROM customers
WHERE company_name LIKE 'F%';
Run in terminal

This query should return 8 rows.

WHERE clause with a BETWEEN operator

In this exercise we'll query the orders table and return just the rows that have an order_id between 10,985 and 11,000.

SELECT order_id,
customer_id,
employee_id,
order_date,
ship_postal_code
FROM orders
WHERE order_id BETWEEN 10985 AND 11000;
Run in terminal

This query should return 16 rows.

WHERE clause with a not equal <> operator

In this exercise we'll query the employees table and return just the rows where the employee_id is not eqal to "1".

SELECT first_name,
last_name,
title,
address,
employee_id
FROM employees
WHERE employee_id &lt;&gt; 1;
Run in terminal

This query should return 8 rows.