programming-examples/sql/Union/9. Write a query that produces the name and number of each salesman and each customer with more than one current order. Put the results in alphabetical order.sql

16 lines
541 B
MySQL
Raw Normal View History

2019-11-18 14:05:53 +01:00
/*9. Write a query that produces the name and number of each salesman and each customer with more than one current order.
Put the results in alphabetical order.*/
SELECT customer_id, cust_name
FROM customer a
WHERE 1<
(SELECT COUNT (*)
FROM orders b
WHERE a.customer_id = b.customer_id)
UNION
SELECT salesman_id, name
FROM salesman a
WHERE 1 <
(SELECT COUNT (*)
FROM orders b
WHERE a.salesman_id = b.salesman_id)
ORDER BY 2;