1
I have the following table:
Tabela: tabela_1
id | id_pessoas | id_empreitadas
-----------------------------------
4357 | 3776 | 37
3949 | 3776 | 3
I have the appointment:
SELECT id_pessoas , MAX(id) max_id, id_empreitadas FROM tabela_1 GROUP BY id_pessoas
This consultation resumes:
id | id_pessoas | id_empreitadas
-----------------------------------
4357 | 3776 | 3
I can’t understand why it takes up the value 3
in the id_empreitadas
and not the 37
. Can you help me?
What you need is the highest id_contract value or do you need the value related to the record that has the highest id? That’s not clear in the question.
– Woss
It doesn’t really bring anything, because the
GROUP BY
make a mistake.– rbz
Basically pq is not how it works. In Sqlite the line returned is always the same in all fields. In Mysql you can return any one. @Rbz depending on configuration. As it is, you need ANY_VALUE( ) to return the others, without Strict it is as if you had applied ANY_VALUE() to them without grouping
– Bacco
The submitted query is incorrect, because in group by you should put all the entries in select. Send the real query you used that returned this record.
– Elisiany Oliveira
What I want is the line data that contains the highest id value. When the query is executed, it resumes the row with the largest id, but the value that resumes in the 'id_contractors' column is the value of another row. The goal is to get the 'id_contractors' column at the highest id value'.
– Mario Cordeiro