Can anyone help me how to select one record per email?
I have the query below:
SELECT a.ID, a.NAME, a.LASTMODIFIED, b.EMAIL
FROM TABLE_A a
JOIN TABLE_B b
ON a.IDA = b.IDB
WHERE a.LASTMODIFIED <= today
ORDER BY b.LASTMODIFIED
it will result :
+------+-------+--------------------------------------+
| id | name | lastmodified | email |
+------+-------+--------------------------------------+
| 1 | aa | 01-JAN-2016 | test01@mail.com |
| 2 | bb | 02-JAN-2016 | test02@mail.com |
| 3 | cc | 03-JAN-2016 | test01@mail.com |
| 4 | dd | 02-JAn-2016 | test03@mail.com |
+------+-------+--------------------------------------+
expected result is :
+------+-------+--------------------------------------+
| id | name | lastmodified | email |
+------+-------+--------------------------------------+
| 2 | bb | 02-JAN-2016 | test02@mail.com |
| 3 | cc | 03-JAN-2016 | test01@mail.com |
| 4 | dd | 02-JAN-2016 | test03@mail.com |
+------+-------+--------------------------------------+
It should return only one email per row, order by lastmodified
date.