CodeBlanks Logo Icon CodeBlanks

String concatenation

Join strings with ||.

BETWEEN and IN

BETWEEN filters a range, IN a list. BETWEEN includes the endpoints.

SELECT name FROM products
WHERE price BETWEEN 10 AND 50
  AND category IN ('kitap', 'kırtasiye');

Price between 10 and 50 and category is book or stationery.

name is selected from products. WHERE keeps only the rows where price BETWEEN 10 AND 50 AND category IN ('kitap', … holds.

BETWEEN and IN — details

IN is shorter than many OR. BETWEEN is equivalent to >= AND <=.

Practice BETWEEN and IN

Select names from products where price is between 10 and 50.

Starter code

query.sql
-- filter range
SELECT name
FROM products
WHERE

Sample solution

query.sql
SELECT name
FROM products
WHERE price BETWEEN 10 AND 50

Expected output

name
Defter
Çanta
Kalem

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Filter list

Question
SELECT name FROM customers
WHERE city ____ ('İzmir', 'Bursa');
Answer
SELECT name FROM customers
WHERE city IN ('İzmir', 'Bursa');

Explanation: IN returns the row when the city is one of the values in the list.

2 String concatenation: match the terms

Term Meaning
BETWEEN range
IN list
LIKE pattern
IS NULL empty

3 Does BETWEEN include endpoints?

  • No
  • Yes, both Correct answer
  • Only the lower one
  • Only the upper one

Explanation: BETWEEN includes both ends.

All lessons in Beginner