w3resource
SQL exercises

SQL UNION Exercises: Display distinct salesman and their cities

SQL UNION: Exercise-2 with Solution

2. Write a query to display distinct salesman and their cities.

Sample table: Salesman


Sample table: Customer


Sample Solution:

SELECT salesman_id, city
FROM customer
UNION
(SELECT salesman_id, city
FROM salesman)

Sample Output:

salesman_id	city
5001	    New York
5002	    London
5002	    California
5006	    Paris
5007	    Rome
5002	    Paris
5005	    London
5003	    Berlin
5007	    Moscow
5003	    San Jose

Practice Online


Inventory database model

Query Visualization:

Duration:

Query visualization of Display distinct salesman and their working cities - Duration

Rows:

Query visualization of Display distinct salesman and their working cities - Rows

Cost:

Query visualization of Display distinct salesman and their working cities - Cost

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a query to display all salesmen and customer located in London.
Next: Write a query to display all the salesmen and customer involved in this inventory management system.

What is the difficulty level of this exercise?



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