w3resource
SQL exercises

SQL Subquery Exercises: Find salesmen with all information who lives in the city where any of the customers lives

SQL SUBQUERY : Exercise-19 with Solution

19. Write a query to find salesmen with all information who lives in the city where any of the customers lives.

Sample table: Salesman


Sample table: Customer


Sample Solution:

SELECT *
FROM salesman 
WHERE city=ANY
    (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 Find salesmen with all information who lives in the city where any of the customers lives - Duration

Rows:

Query visualization of Find salesmen with all information who lives in the city where any of the customers lives - Rows

Cost:

Query visualization of Find salesmen with all information who lives in the city where any of the customers lives - Cost

Contribute your code and comments through Disqus.

Previous: Write a query that extract the rows of all salesmen who have customers with more than one orders.
Next: Write a query to find all the salesmen for whom there are customers that follow them.

What is the difficulty level of this exercise?



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