Sales Person

You can write a MySQL query to find the names of all salespersons who did not have any orders related to the company with the name “RED”. Here’s the query:

1
2
3
4
5
6
7
8
SELECT name
FROM SalesPerson
WHERE sales_id NOT IN (
  SELECT sales_id
  FROM Orders
  JOIN Company ON Orders.com_id = Company.com_id
  WHERE Company.name = 'RED'
);

Explanation:

  • The subquery in the WHERE clause gets the sales_id of all salespersons who have orders related to the company with the name “RED”.
  • The main query then selects the names of all salespersons from the SalesPerson table whose sales_id is not found in the subquery’s result, i.e., the ones who did not have any orders related to “RED”.