Simple Query ✅ | With Proper Explanation 🤝
IntuitionThe problem requires us to find all pairs of actors and directors who have worked together on at least three movies. This means we need to identify fre
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem requires us to find all pairs of actors and directors who have worked together on at least three movies. This means we need to identify frequent collaborations between actors and directors by counting how many times each pair appears in the ActorDirector table.

# Approach
<!-- Describe your approach to solving the problem. -->
1.	Group the data: We use GROUP BY actor_id, director_id to group records based on the actor_id and director_id, ensuring that each unique pair is considered.

2.	Count the occurrences: Using COUNT(*), we count how many times each actor-director pair appears in the table, which represents the number of movies they have worked on together.

3.	Filter out pairs with fewer than 3 collaborations: The HAVING clause ensures that only pairs where COUNT(*) >= 3 are included in the result.

4.	Select the required columns: Finally, we retrieve actor_id and director_id for the qualifying pairs.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
If you found my solution helpful, I’d really appreciate it if you could give it an upvote! 🙌 Your support keeps me motivated to share more simple and efficient solutions. Thank you! 😊 

# Code
```postgresql []
-- Write your PostgreSQL query statement below
SELECT actor_id, director_id
FROM ActorDirector
GROUP BY actor_id, director_id
HAVING COUNT(*) >= 3
```
['PostgreSQL']