w3resource
SQL exercises

SQL UNION Exercises: Display all the salesmen and customer involved in this inventory management system

SQL UNION: Exercise-3 with Solution

3. Write a query to display all the salesmen and customer involved in this inventory management system.

Sample table: orders


Sample table: customer


Sample Solution:

SELECT salesman_id, customer_id
FROM customer
UNION 
(SELECT salesman_id, customer_id
FROM orders)

Sample Output:

salesman_id	customer_id
5005		3001
5007		3003
5001		3007
5002		3008
5006		3004
5003		3009
5001		3002
5002		3005

Practice Online


Inventory database model

Query Visualization:

Duration:

Query visualization of Display all the salesmen and customer involved in this inventory management system - Duration

Rows:

Query visualization of Display all the salesmen and customer involved in this inventory management system - Rows

Cost:

Query visualization of Display all the salesmen and customer involved in this inventory management system - Cost

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

Previous: Write a query to display distinct salesman and their cities.
Next: Write a query to make a report of which salesman produce the largest and smallest orders on each date.

What is the difficulty level of this exercise?



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