Hello!
In pseudo-SQL it would be like this:
"GROUP all items in products_table
by similar name
. Then, EVERY FIRST element in each GROUP is given the '1' in the field leader
".
Here is an example:
Stage 1
+----+---------+--------+
| id | name | leader |
+----+---------+--------+
| 1 | Foo | 0 |
+----+---------+--------+
| 2 | Baz | 0 |
+----+---------+--------+
| 3 | Bar | 0 |
+----+---------+--------+
| 4 | Baz | 0 |
+----+---------+--------+
| 5 | Foo | 0 |
+----+---------+--------+
| 6 | Bar | 0 |
+----+---------+--------+
| 7 | Baz | 0 |
+----+---------+--------+
| 8 | Bar | 0 |
+----+---------+--------+
| 9 | Bar | 0 |
Stage 2
`
+----+---------+--------+
| id | name | leader |
+----+---------+--------+
| 1 | Foo | 0 |
+----+---------+--------+
| 5 | Foo | 0 |
+----+---------+--------+
| 2 | Baz | 0 |
+----+---------+--------+
| 4 | Baz | 0 |
+----+---------+--------+
| 7 | Baz | 0 |
+----+---------+--------+
| 3 | Bar | 0 |
+----+---------+--------+
| 6 | Bar | 0 |
+----+---------+--------+
| 8 | Bar | 0 |
+----+---------+--------+
| 9 | Bar | 0 |
`
Stage 3
+----+---------+--------+
| id | name | leader |
+----+---------+--------+
| 1 | Foo | 1 |
+----+---------+--------+
| 5 | Foo | 0 |
+----+---------+--------+
| 2 | Baz | 1 |
+----+---------+--------+
| 4 | Baz | 0 |
+----+---------+--------+
| 7 | Baz | 0 |
+----+---------+--------+
| 3 | Bar | 1 |
+----+---------+--------+
| 6 | Bar | 0 |
+----+---------+--------+
| 8 | Bar | 0 |
+----+---------+--------+
| 9 | Bar | 0 |
`
Is it possible to do this without iterating over each row in the table and finding similar rows by their name
? There are 1 500 000 rows in there and it will be quite slow. I wish this could be done in no more than about 30 minutes.
Thank you !