I have the below tables:
order_temp table
|---------------------|------------------|------------------|
| order_id | sap_number | product_name |
|---------------------|------------------|------------------|
| 1 | 123 | earphones |
|---------------------|------------------|------------------|
| 2 | 123 | battery |
|---------------------|------------------|------------------|
| 3 | 456 | charger |
|---------------------|------------------|------------------|
| 4 | 789 | phone |
|---------------------|------------------|------------------|
order table
|---------------------|------------------|
| order_id | sap_number |
|---------------------|------------------|
| 1 | 123 |
|---------------------|------------------|
| 2 | 456 |
|---------------------|------------------|
| 3 | 789 |
|---------------------|------------------|
I want to insert data in order_item table which should have the same order_id if the sap_number is same. It should look like this:
order_item table:
|---------------------|------------------|------------------|
| order_item_id | order_id | product_name |
|---------------------|------------------|------------------|
| 1 | 1 | earphones |
|---------------------|------------------|------------------|
| 2 | 1 | battery |
|---------------------|------------------|------------------|
| 3 | 2 | charger |
|---------------------|------------------|------------------|
| 4 | 3 | phone |
|---------------------|------------------|------------------|
Please help me with an insert query for order_item table.