1
I have a problem in a SQL
where I need to find the biggest date of a ID
specific, where it has several records of this same ID
:
Dice:
ID - date - name
2 - 10/10/2004 - cesar
5 - 10/10/2008 - Japan
4 - 10/10/2002 - maria
1 - 04/01/2017 - paulo
1 - 12/12/2017 - paulo
4 - 10/10/2000 - Maria
5 - 10/10/2017 - Japan
In this example I would like to seek the ID = 1
which corresponds to the name Paul and I need the highest date in specific, then followed my SQL
where I seek the greatest date, but the name comes another and not the ID
referent.
SELECT MAX(data) as data, nome FROM teste WHERE id = '1'
Result ... 1 - 12/12/2017 - cesar
Expected ... 1 - 12/12/2017 - paulo
I mean, I realized I get my first name back from the bank, and it’s not what I need.
tried to group? something like that:
SELECT MAX(data) as data, nome FROM teste WHERE id = 1 group by id
– BrTkCa
yes, and brings everyone with ID 1
– Thiago Lopez
Do it the other way around, first get all the entries with id = 1 and then see which one is the biggest
– lazyFox