Very quick one:
I’ve done this before, but having a bit of a mind blank right now.
SELECT max(id) as id, username, email
FROM user_info
WHERE username!=''
GROUP by id,email
Unfortunately this is not working. It will select the max id but not then the corresponding data from that row.
If you have multiple ids per email address, then you can usemax(id)and group by the email only.You can use a subquery which will return the max id in the subquery and then you use that to self join on the table to return the most recent id, username and email:
See SQL Fiddle with Demo