Md Ismail
PRO
last month
Mdcountry asked

The instruction here says: "Write an SQL query to select all the columns from the Products table whose price is between 145 and 220, excluding 145 and 220." I don't understand what excluding 145 and 220 means.

Udayan Shakya
Expert
last month
Udayan Shakya answered

Hi there!

The problem statement is instructing you to select those rows from the Products table whose price is between 145 and 220, BUT the query should not select those rows whose price is either exactly 145 or 220.

This is basically a trick question because if you use the following query, then your solution will be wrong:

SELECT *
FROM Products
WHERE price BETWEEN 145 AND 220;

It's because BETWEEN will also select those rows whose price is 145 or 220.

So if you want to solve this problem using the BETWEEN operator, you need to use BETWEEN 146 AND 219.

This way, you've successfully excluded 145 and 220.

Correct Solution

SELECT *
FROM Products
WHERE price BETWEEN 146 AND 219;

Hope this helps! Let me know if you have more questions.

SQL
This question was asked as part of the Learn SQL Basics course.