w3resource
SQL exercises

SQL Subquery Exercises: Display the salesmen which name are alphabetically lower than the name of the customers

SQL SUBQUERY: Exercise-21 with Solution

21. Write a query to display the salesmen which name are alphabetically lower than the name of the customers.

Sample table: Salesman


Sample table: Customer


Sample Solution:

SELECT *
FROM salesman a
WHERE EXISTS
   (SELECT *
	FROM CUSTOMER b
	WHERE  a.name  < b.cust_name);

Output of the Query:

salesman_id	name		city		commission
5001		James Hoog	New York	0.15
5002		Nail Knite	Paris		0.13
5006		Mc Lyon		Paris		0.14
5003		Lauson Hen	San Jose	0.12

Explanation:

SQL Subqueries: Display the salesmen which name are alphabetically lower than the name of the customers.

Practice Online


Inventory database model

Query Visualization:

Duration:

Query visualization of Display the salesmen which name are alphabetically lower than the name of the customers - Duration

Rows:

Query visualization of Display the salesmen which name are alphabetically lower than the name of the customers - Rows

Cost:

Query visualization of Display the salesmen which name are alphabetically lower than the name of the customers - Cost

Contribute your code and comments through Disqus.

Previous: Write a query to find all the salesmen for whom there are customers that follow them.
Next: Write a query to display the customers who have a greater gradation than any customer who belongs to the alphabetically lower than the city New York.

What is the difficulty level of this exercise?