user49126
user49126

Reputation: 1863

multiple insert from a subquery

I have a query which will return some ids.

SELECT ID FROM xf_menu WHERE m.modul_id = 13;

Then there is a simple insert query

INSERT INTO xp_uziv_menu (menu_id, modul_id, right)  VALUES (???, 136, 3);

the values 136 and 3 are constants.

I'm wondering if is it possilbe to write a query where the ids would be passed from the first query to the insert query and executed.

I tried this syntax but it doesn't work.

INSERT INTO 
     xp_uziv_menu (menu_id, modul_id, right)  
VALUES 
     (SELECT ID FROM xf_menu WHERE m.modul_id = 13, 136, 3);

Upvotes: 0

Views: 383

Answers (3)

Arion
Arion

Reputation: 31239

Maybe something like this:

INSERT INTO xp_uziv_menu (menu_id, modul_id, right)   
SELECT 
    ID,
    136,
    3 
FROM xf_menu WHERE m.modul_id = 13;

Upvotes: 4

aF.
aF.

Reputation: 66697

Try it this way:

INSERT INTO xp_uziv_menu (menu_id, modul_id, right)  
SELECT ID, 136, 3 FROM xf_menu WHERE m.modul_id = 13;

Upvotes: 2

James Anderson
James Anderson

Reputation: 27478

Try:-

INSERT INTO xp_uziv_menu
 SELECT ID, modul_id, 3 Where id = 13

Upvotes: 0

Related Questions