programming-examples/sql/Union/6. Write a query to list all the salesmen, and indicate those who do not have customers in their cities, as well as whose who do.sql
2019-11-18 14:05:53 +01:00

12 lines
428 B
SQL

/*6. Write a query to list all the salesmen, and indicate those who do not have customers in their cities, as well as whose
who do.*/
SELECT salesman.salesman_id, name, cust_name, commission
FROM salesman, customer
WHERE salesman.city = customer.city
UNION
SELECT salesman_id, name, 'NO MATCH', commission
FROM salesman
WHERE NOT city = ANY
(SELECT city
FROM customer)
ORDER BY 2 DESC;