V
V
Vlad2017-09-27 17:19:29
MySQL
Vlad, 2017-09-27 17:19:29

How to rework SQL database?

Please help me to create a SQL query or macro for Excel that would allow me to run through the entire table and find duplicate values ​​in the fields. And then if the value is repeated, then take the ID of the first element and register it for all other repetitions.
1 - value1
2 - value2
3 - value3
4 - value1
5 - value1
6 -
value2 add
1 - value1 - 1
2 - value2 - 2
3 - value3 - 3
4 - value1 - 1
5 - value1 - 1
6 - value2 - 2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-09-27
@Sc0undRel

UPDATE `table` AS `t`
  JOIN (
    SELECT MIN(`id`) AS `min`, `value`
      FROM `table`
      GROUP BY `value`
  ) AS `t1` ON `t1`.`value` = `t`.`value`
  SET `t`.`min_id` = `t1`.`min`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question