Jada Developer
Jada Developer

Reputation: 126

INSERT Multiple with SELECT

i'm trying to use INSERT into with SELECT DISTINCT and this is what i tried so far.

INSERT INTO creature_loot_template VALUES (id, 68910, 0, 100, 1, 1, 0, 1, 1, NULL)
SELECT DISTINCT id FROM creature WHERE map = 389;

So this is example of what it should do (there is more than 20 - 40 lines:

INSERT INTO creature_loot_template VALUES (123, 68910, 0, 100, 1, 1, 0, 1, 1, NULL);
INSERT INTO creature_loot_template VALUES (124, 68910, 0, 100, 1, 1, 0, 1, 1, NULL);
INSERT INTO creature_loot_template VALUES (125, 68910, 0, 100, 1, 1, 0, 1, 1, NULL);
INSERT INTO creature_loot_template VALUES (125, 68910, 0, 100, 1, 1, 0, 1, 1, NULL);

I've also tried the following SQL's :

INSERT INTO creature_loot_template VALUES ((SELECT DISTINCT id FROM creature WHERE map = 389), 68910, 0, 100, 1, 1, 0, 1, 1, NULL);
SET
@id = (SELECT DISTINCT id FROM creature WHERE map = 389);
INSERT INTO creature_loot_template VALUES (@id, 68910, 0, 100, 1, 1, 0, 1, 1, NULL);

Upvotes: 1

Views: 68

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269923

Just list the values you want on the SELECT:

INSERT INTO creature_loot_template
    SELECT DISTINCT id, 68910, 0, 100, 1, 1, 0, 1, 1, NULL
    FROM creature
    WHERE map = 389;

I would recommend that you list all the columns in the INSERT as well. This ensures that the code does what you actually want.

Upvotes: 2

Related Questions