insert into all possible combination of arrays of strings I have a users table it has 3 columns

First Name |  Last Name  | Email 


I have

first names = ["a1", "a2", "a3", "a4"]
last names = ["b1", "b2", "b3", "b4"]
email = ["e1", "e2", "e3", "e4"]


now i want to insert users table by

all combinations of the string arrays.

like below.

First Name | Last Name | Email 
 a1        | b1        | e1
 a2        | b1        | e1
 a3        | b1        | e1
....
 a1        | b2        | e1
 a1        | b3        | e1
.....
 a1        | b1        | e1
 a1        | b1        | e2


in this above way of all combinations.
You just need to do a cartesian product:

INSERT INTO mytable("First Name", "Last Name", "Email")
    SELECT * FROM (
        SELECT 'a1' AS firstname
        UNION SELECT 'a2'
        UNION SELECT 'a3'
        UNION SELECT 'a4'
    ) AS t1, (
        SELECT 'b1' AS lastname
        UNION SELECT 'b2'
        UNION SELECT 'b3'
        UNION SELECT 'b4'
    ) AS t2, (
        SELECT 'e1' AS email
        UNION SELECT 'e2'
        UNION SELECT 'e3'
        UNION SELECT 'e4'
    ) AS t3
;


(for mysql, replace " by ` or set sql_mode to include ANSI_QUOTES)

Alternate shorter syntax for PostgreSQL:

INSERT INTO table("First Name", "Last Name", "Email")
    SELECT * FROM (
        VALUES('a1'), ('a2'), ('a3'), ('a4')
    ) AS t1(firstname), (
        VALUES('b1'), ('b2'), ('b3'), ('b4')
    ) AS t2(lastname), (
        VALUES('e1'), ('e2'), ('e3'), ('e4')
    ) AS t3(email)
;


For PostgreSQL and from arrays:

INSERT INTO table("First Name", "Last Name", "Email")
    SELECT * FROM (
        SELECT unnest(ARRAY['a1', 'a2', 'a3', 'a4'])
    ) AS t1(firstname), (
        SELECT unnest(ARRAY['b1', 'b2', 'b3', 'b4'])
    ) AS t2(lastname), (
        SELECT unnest(ARRAY['e1', 'e2', 'e3', 'e4'])
    ) AS t3(email)
;