0

Currently I duplicate some records from one table and insert to second table.

   $sql = "INSERT INTO pending_payments (user_id, course_id, amount)
    SELECT user_id,course_id,monthly_subscription_fee
    FROM enrol
    WHERE active_shop='1'";

Okay, but Now I duplicate this records: user_id,course_id,monthly_subscription_fee

and I need add some custom values.

I show on second query:

$sql = "INSERT INTO pending_payments (data_added, type_fee)
    VALUES ('_current_data', 'subscription');

Can anyone help me merge this both sql query into one? to run at the same time?

enter image description here

Shadow
  • 33,525
  • 10
  • 51
  • 64
TOM ARM
  • 51
  • 3
  • When you want to insert data into an existing record, you should use [UPDATE](https://dev.mysql.com/doc/refman/8.0/en/update.html) – Luuk Feb 06 '22 at 10:40
  • this is sql which runs cron and creates pending payments. So I don't want to use update - just create this record with all the values at once according to screenshot. So i need update only current created records (not all records in table). Can you help me? – TOM ARM Feb 06 '22 at 10:44
  • Just change your SELECT statement to include these extra columns and their values – NickW Feb 06 '22 at 10:46
  • It is totally unclear why you did not try/do: `INSERT INTO pending_payments (user_id, course_id, amount, data_added, type_fee) SELECT user_id, course_id, monthly_subscription_fee, '_current_data', 'subscription') WHERE active_shop='1'";` – Luuk Feb 06 '22 at 10:49

0 Answers0