A comma-separated list of values ​​as separate rows, not as fields for a single row, for SQL INSERT

I want to make many attachments in a single SQL statement, pretty much similar to
INSERT INTO xxx SELECT field FROM zzz

But with values ​​that I don't have in the table, and this is just a list of literals.
The usual way would be to execute one SQL query for each value, but if there is a standard SQL query or MySQL-specific, it would be great.

+4
source share
2 answers

insert into xxx (fields) values (values1), (values2), (values3)

eg insert into mytable (name, desc) values ('name1','desc1'), ('name2','desc2'), ('name3','desc3'), ('name4','desc4')

+5
source
 insert into xxx(afield) select 'a' union select 'b' union select 'x' 

will give you a table:

in field

a

b

x

+2
source

Source: https://habr.com/ru/post/1306478/


All Articles