✔️ NOT IN
IntuitionWe use NOT IN to filter out salespersons who have orders related to the company "RED".Approach
The inner-most query selects the com_id of the company n
# Intuition
We use `NOT IN` to filter out salespersons who have orders related to the company `"RED"`.

# Approach
1. The inner-most query selects the `com_id` of the company named `"RED"`.
2. The middle query selects the `sales_id` of salespersons who have placed orders for the company `"RED"`.
3. The outer query selects all salespersons whose `sales_id` is NOT in the list of salespersons who have orders related to `"RED"`.

# Code
```mysql []
SELECT name 
FROM SalesPerson 
WHERE sales_id NOT IN (
    SELECT DISTINCT sales_id 
    FROM Orders 
    WHERE com_id IN (
        SELECT com_id 
        FROM Company 
        WHERE name = 'RED'
    )
);
```

---

![upvote.png](https://assets.leetcode.com/users/images/8acff4d0-a57a-437a-bb43-8a756d945c0a_1741715544.8880363.png)

['MySQL']