programming-examples/sql/Union/7. Write a query to that appends strings to the selected fields, indicating whether or not a specified salesman was matched to a customer in his city.sql

12 lines
421 B
MySQL
Raw Normal View History

2019-11-18 14:05:53 +01:00
/*7. Write a query to that appends strings to the selected fields, indicating whether or not a specified salesman was matched
to a customer in his city.*/
SELECT a.salesman_id, name, a.city, 'MATCHED'
FROM salesman a, customer b
WHERE a.city = b.city
UNION
SELECT salesman_id, name, city, 'NO MATCH'
FROM salesman
WHERE NOT city = ANY
(SELECT city
FROM customer)
ORDER BY 2 DESC;