I have 2 tables, stock and store
stock:
|-----------------|
| Id | store_id |
|-----|-----------|
| 1 | |
|-----|-----------|
| 2 | |
|-----|-----------|
| 3 | |
|-----|-----------|
| 4 | |
|-----|-----------|
store:
|-----------------|
| Id | name |
|-----|-----------|
| 21| aaaa |
|-----|-----------|
| 12| bbbb |
|-----|-----------|
I need to loop over store table and and put its id in stock table's store_id column, the result should be:
|-----------------|
| Id | store_id |
|-----|-----------|
| 1 | 21 |
|-----|-----------|
| 2 | 12 |
|-----|-----------|
| 3 | 21 |
|-----|-----------|
| 4 | 12 |
|-----|-----------|
I have tried some example like Postgresql Update inside For Loop
But didn't get a solution... plz help
id? Or something else? By "and so on", you mean alternatingly?