SQL Exercises: Using where clause with between operator
From the following table, write a SQL query to retrieve the details of the salespeople whose names begin with any letter between 'A' and 'L' (not inclusive). Return salesman_id, name, city, commission.
Sample table: salesman
salesman_id | name | city | commission -------------+------------+----------+------------ 5001 | James Hoog | New York | 0.15 5002 | Nail Knite | Paris | 0.13 5005 | Pit Alex | London | 0.11 5006 | Mc Lyon | Paris | 0.14 5007 | Paul Adam | Rome | 0.13 5003 | Lauson Hen | San Jose | 0.12
Sample Solution:
-- This query selects all columns from the 'salesman' table.
SELECT *
-- Specifies the table from which to retrieve the data (in this case, 'salesman').
FROM salesman
-- Filters the rows to only include those where the 'name' column is between 'A' and 'L'.
WHERE name BETWEEN 'A' AND 'L';
Output of the Query:
salesman_id name city commission 5001 James Hoog New York 0.15
Code Explanation:
The given SQL query selects all columns (*) from the 'salesman' table where the value of the "name" column is alphabetically between 'A' and 'L' (inclusive) . This query returns all the rows with names that start with letter between A and L.
Relational Algebra Expression:

Relational Algebra Tree:

Explanation:

Visual presentation :

Practice Online
For more Practice: Solve these Related Problems:
- Write a SQL query to retrieve the details of salespeople whose names begin with any letter between 'M' and 'P' (not inclusive). Return salesman_id, name, city, commission.
- Write a SQL query to find the details of salespeople whose names start with the letter 'J'. Return salesman_id, name, city, commission.
- Write a SQL query to retrieve the details of salespeople whose names end with the letter 'n'. Return salesman_id, name, city, commission.
- Write a SQL query to list all salespeople whose names contain the letter 'a'. Return salesman_id, name, city, commission.
Contribute your code and comments through Disqus.
Previous SQL Exercise: Using between, not and in operators to filter records.
Next SQL Exercise: Using where clause with not and between operators.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics