I have a data set that looks like this example data set.
There are multiple users under one domain. I want only one row per email_domain and the row should correspond to the max(last_login) value. In short I only want the user from the email_domain who was the last to log in among all users from the same domain.
Ive tried a query which looks like this
select *
FROM
(
select LOWER(SUBSTRING(ua.email FROM POSITION ('@' IN ua.email) + 1)) AS email_domain, last_login, last_name, first_name, email, phone
from user_with_address ua
order by email_domain
) as A
group by email_domain, last_login, last_name, first_name, email, phone
having last_login = max(last_login)
order by email_domain
I still get a list with multiple values for each email domain, what am I doing wrong? Please help.
Disclaimer: I have basic->intermediate knowledge of SQL.