我具有以下表格结构:
leads:
name | email | date
-------------------------------------------------------
John | [email protected] | 2020-01-21
J | [email protected] | 2020-01-20
Alex | [email protected] | 2020-01-19
A | [email protected] | 2020-01-18
James | [email protected] | 2020-01-17
我只需要选择带有UNIQUE电子邮件和最新关联名称的行,这样预期的结果是:
name | email | date
-------------------------------------------------------
John | [email protected] | 2020-01-21
Alex | [email protected] | 2020-01-19
James | [email protected] | 2020-01-17
不存在使用
select * from tbl a
where not exist(select 1 from tbl b where a.email = b.email and a.date < b.date)