Search code examples
mysqlselectinsert-into

MYSQL insert from select and variables


I am trying to insert values coming from a select and variable :

INSERT INTO routeur (`codeAdherent`, `quantiteArticle`, `dateFin`) VALUES 
(SELECT `codeAdherent` FROM adherents WHERE categorie = 'G', `quantiteArticle` = $a, `dateFin`= $b);

Write it with and without VALUES, with and without IN, with and without brackets but I always get an synthax error.

Where is my mistake?


Solution

  • Try below:

    INSERT INTO routeur (codeAdherent, quantiteArticle, dateFin) 
    SELECT codeAdherent, @a, @b FROM adherents WHERE categorie = 'G'