-1
hello friends I have a table and I would like to update the records in order to take the NAMES that repeat and put as ACTIVE = 0 only which DATA_CADASTRO are old!
table:
+--------------------------------------------------+
| pessoas |
+----+--------+------+---------------------+-------+
| id | nome | time | data_cadastro | ativo |
+----+--------+------+---------------------+-------+
| 1 | luiz | A | 2019-10-05 10:52:01 | 1 |
+----+--------+------+---------------------+-------+
| 2 | carlos | B | 2019-10-20 20:52:01 | 1 |
+----+--------+------+---------------------+-------+
| 3 | maria | C | 2019-09-15 10:50:30 | 1 |
+----+--------+------+---------------------+-------+
| 4 | maria | C | 2019-09-16 10:40:50 | 1 |
+----+--------+------+---------------------+-------+
| 5 | carlos | B | 2019-10-20 20:55:01 | 1 |
+----+--------+------+---------------------+-------+
the result you would like to appear
+--------------------------------------------------+
| pessoas |
+----+--------+------+---------------------+-------+
| id | nome | time | data_cadastro | ativo |
+----+--------+------+---------------------+-------+
| 1 | luiz | A | 2019-10-05 10:52:01 | 1 |
+----+--------+------+---------------------+-------+
| 2 | carlos | B | 2019-10-20 20:52:01 | 0 |
+----+--------+------+---------------------+-------+
| 3 | maria | C | 2019-09-15 10:50:30 | 0 |
+----+--------+------+---------------------+-------+
| 4 | maria | C | 2019-09-16 10:40:50 | 1 |
+----+--------+------+---------------------+-------+
| 5 | carlos | B | 2019-10-20 20:55:01 | 1 |
+----+--------+------+---------------------+-------+
I’m trying like this:
"UPDATE people ACTIVE SET=0 WHERE NAME= 'maria'"
however this changing all registration name='maria' without picking up the oldest data_cadastro
I accept all help and improvements...
Search by EXISTS
– Motta
This is pretty vague @Motta, explain better how exists will solve this problem?
– Ricardo Pontual