DzikiChrzan
DzikiChrzan

Reputation: 3107

SELECT inside of INSERT

This part of code :

INSERT INTO koszyk_produkt (ID_koszyk,ID_produkt,Ilosc) 
VALUES (
(SELECT ID FROM koszyk 
WHERE ID_klient=IDk),
IDp,Ilosc);

works perfectly fine when tested in HeidiSQL (MariaDB), but fails with two errors when I try to apply this in phpMyAdmin (the same engine):

A comma or a closing bracket was expected (near SELECT)
Unexpected token. (near ID)

I'm lack of ideas how to make this work.

@EDIT
I forgot to add - this is procedure, and IDk IDp Ilosc are arguments.

Upvotes: 1

Views: 305

Answers (1)

JamieD77
JamieD77

Reputation: 13949

You can select the ID and use the arguments as the 2nd and 3rd columns.

INSERT  INTO koszyk_produkt
        (ID_koszyk,ID_produkt,Ilosc)
SELECT  ID,
        IDp,
        Ilosc
FROM    koszyk
WHERE   ID_klient = IDk

Upvotes: 2

Related Questions