How to unify two records with same field? I have a table that get records like below:

SELECT cod, name, doc1, cpf, the result is:

cod | name  | doc1 | cpf
   1 | john  |   12 |   0
   1 | john  |    0 | 123
   2 | mary  |   25 |   0
   2 | mary  |    0 | 456
   3 | andy  |   48 |   0
   3 | andy  |   55 | 789

How to unify the registers with some cod like the result below?

cod | name | doc1 | doc2 | cpf
   1 | john |   12 |    0 | 123
   2 | mary |   25 |    0 | 456
   3 | andy |   48 |   55 | 789
Use GROUP BY to get one output row per cod, and use aggregate functions to select one value to output. For the doc values, use CASE to select only one of them (it returns NULL in a row where it does not match):

SELECT cod,
       name,
       max(CASE date_row WHEN 1 THEN doc1 END) AS doc1,
       max(CASE date_row WHEN 2 THEN doc1 END) AS doc2,
       max(cpf) AS cpf
FROM my_table
GROUP BY cod,
         name
ORDER BY cod;