Hello!
**In pseudo-SQL it would be like this:
“GROUP all items in `products_table`name`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
Thank you !