I'm trying to select rows from a table, one row per email address, and return one firstname from the top row in the email list. The query, though, returns multiple email addresses. What am I doing wrong?
SELECT
DISTINCT email,
(SELECT TOP 1 firstname
FROM onsite_clients_archive oc
WHERE oc.client_id=oca.client_id
ORDER BY client_id)
FROM onsite_clients_archive oca
WHERE users_user_id IS NULL