w3resource
SQL exercises

SQL Subquery Exercises: Display the salesmen for whom there are customers that follow them

SQL SUBQUERY: Exercise-20 with Solution

20. Write a query to find all the salesmen for whom there are customers that follow them.

Sample table: Salesman


Sample table: Customer


Sample Solution:

SELECT *
FROM salesman 
WHERE city IN
    (SELECT city
     FROM customer);

Sample Output:

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

Practice Online


Inventory database model

Query Visualization:

Duration:

Query visualization of Display the salesmen for whom there are customers that follow them - Duration

Rows:

Query visualization of Display the salesmen for whom there are customers that follow them - Rows

Cost:

Query visualization of Display the salesmen for whom there are customers that follow them - Cost

Contribute your code and comments through Disqus.

Previous: Write a query to find salesmen with all information who lives in the city where any of the customers lives.
Next: Write a query to display the salesmen which name are alphabetically lower than the name of the customers.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming