David Borough
David Borough

Reputation: 33

Insert a row in another table for each row in another table that meets a criteria

I need to insert a new row into one table CUSTOMER_NOTESfor each row in another table CUSTOMER that meets a condition.

If CUSTOMER table column CURRENT is marked as 1, then I need to shove a note into the CUSTOMER_NOTES table, like "THIS IS A CURRENT CUSTOMER". So, if there are 50 current customers (and 240 total customers), there would be 50 entries shoved into the CUSTOMER_NOTES table with the VALUE being "THIS IS A CURRENT CUSTOMER".

Upvotes: 1

Views: 3112

Answers (1)

Felix Pamittan
Felix Pamittan

Reputation: 31879

Assuming your CUSTOMER and CUSTOMER_NOTES has a column CUSTOMER_ID:

INSERT INTO CUSTOMER_NOTES(
    CUSTOMER_ID, 
    NOTES
)
SELECT
    CUSTOMER_ID,
    'THIS IS A CURRENT CUSTOMER'
FROM CUSTOMER
WHERE
    [CURRENT] = 1

Upvotes: 3

Related Questions