I have a problem with a SQL
where I need to search for the largest date of a specified ID
, where it has several records of this ID
:
Data:
ID - date - name
2 - 10/10/2004 - cesar
5 - 10/10/2008 - joana
4 - 10/10/2002 - maria
1 - 04/01/2017 - paulo
1 - 12/12/2017 - paulo 4 - 10/10/2000 - maria 5 - 10/10/2017 - joana
In this example I would like to find the ID = 1
that corresponds to the name paulo and I need the highest date in specific, then I follow my SQL
where I look for the largest date, but the name comes from another one and not from ID
.
SELECT MAX(data) as data, nome FROM teste WHERE id = '1'
Results ... 1 - 12/12/2017 - cesar
Expected ... 1 - 12/12/2017 - paulo
That is, I realized that the first name of the Bank returns to me, and it is not what I need.