Is possible to INSERT List instead of String?


I’m trying to learn more with SQL and I am trying to INSERT a List of Numbers linked with 1 ID (row).

Now I figured out how to use List in SELECT, basics like

SELECT * FROM products WHERE catalog_number IN ("CAT1", "CAT2", "CAT3");

and I am trying to do a similar thing but with INSERT

Something like this but this won’t work, sadly.

INSERT INTO link_products ('main_product_id', 'linked_product_id') VALUES (124, IN(1,2,3,4,))

Basicly I am trying to do like php foreach command fully in SQL (in phpmyadmin) and I am not even sure if this is possible.

The result should be (in database):

id | main_product_id | linked_product_id
1          124               1
2          124               2
3          124               3
4          124               4 


Just insert the data like:

INSERT INTO link_products ('main_product_id', 'linked_product_id') 
VALUES (124, 1)
      ,(124, 2)
      ,(124, 3)
      ,(124, 4)

Answered By – Esteban P.

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published