'Get the first created user per organization

SELECT email, org_id, MIN(created_at) as first_user_created
FROM users
WHERE org_id IN (SELECT org_id FROM subscriptions)
GROUP BY email, org_id;

Result of the above query gives me multiple user records per org_id.

What I want: Per organization - return the email, org_id and first_user_created of user that got created the earliest.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source