w3resource

SQL Exercises: Using where clause with not and between operators

SQL Wildcard & Special Operator: Exercise-8 with Solution

From the following table, write a SQL query to find the details of all salespeople except those whose names begin with any letter between 'A' and 'M' . 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 not between 'A' and 'L'.
WHERE name NOT BETWEEN 'A' AND 'L';

Output of the Query:

salesman_id	name		city		commission
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

Relational Algebra Expression:

Relational Algebra Expression: Using where clause with not and between operators.

Relational Algebra Tree:

Relational Algebra Tree: Using where clause with not and between operators.

Explanation:

Syntax of using where clause with not and between operators

Visual presentation :

Result of using where clause with not and between operators

Practice Online


Query Visualization:

Duration:

Query visualization of Using where clause with not and between operators - Duration

Rows:

Query visualization of Using where clause with not and between operators - Rows

Cost:

Query visualization of Using where clause with not and between operators - Cost

Contribute your code and comments through Disqus.

Previous SQL Exercise: Using where clause with between operator.
Next SQL Exercise: Using where clause with like operator.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/sql-exercises/sql-wildcard-special-operator-exercise-8.php