Easy MySQL Solution | O(1) | With Explanation
IntuitionTo find the customer who brought all the products, wee need to compare the distinct number of products bought by each customer from Customer table, mus
# Intuition
To find the customer who brought all the products, wee need to compare the distinct number of products bought by each customer from Customer table, must be equal to the distinct number of products present in the Products table.

# Approach
1. Select the output as `customer_id` from Customer table.
2. Perform group by operation on `Customer` column.
3. As we are comparing using an `Aggregate function` the condition must be given in the `HAVING` clause.
4. Lastly compare with `Distinct` count of Products from `Product` table.

# Complexity
- Time complexity: **O(n+m)** for n=number of customers from `Customer` table and m=number of products from `Product` table.

- Space complexity: **O(1)** because no additional space required.

# Code
```mysql []
# Write your MySQL query statement below

SELECT customer_id
FROM Customer
GROUP BY customer_id
HAVING COUNT(DISTINCT product_key) = (SELECT COUNT(DISTINCT product_key) FROM Product);

```
['MySQL']