I want to eliminate the duplicate rows based on email from the table and retrieve all the rows without duplicates.
I have tried using distinct but I’m not getting desired results.
SELECT
DISTINCT Email
FROM
Users
Example Table:
Id | Username | |
---|---|---|
1 | [email protected] | sam1122 |
2 | [email protected] | john1122 |
3 | [email protected] | sam2233 |
4 | [email protected] | lily@as |
What I want to retrieve:
Id | Username | |
---|---|---|
1 | [email protected] | john1122 |
2 | [email protected] | lily@as |
5
Answers
We can try using exists logic here:
You can do it using
left join
:Demo here
Yet another option, if you are using MySQL 8 –