List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:September 24 1999 1:34pm
Subject:Re: SQL - INSERT from existing table with extra values to new
table
View as plain text  
At 7:37 AM -0500 9/24/99, Erik Andersson wrote:
>This is probably a rather simple SQL question. I think that my example will
>speak for it self. I need to insert three values into a table. Yet one of
>them is one that I want to grep from another table. It looks like this
>
>INSERT INTO orderrow (
>    customer_id,
>    product_id,
>    orderrow_quantity
>)
>VALUES (SELECT customer_id FROM customer WHERE
>customer_login='user'),(123,321);
>
>
>The documentation says this
>
>    INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
>        [INTO] tbl_name [(col_name,...)]
>        VALUES (expression,...),(...),...
>
>
>... which I think is what I'm doing. The error I get is the following
>
>ERROR 1064: You have an error in your SQL syntax near 'SELECT customer_id
>FROM customer WHERE customer_login='erik'),(123,321)' at line 6

In that syntax, expression is an expression, not an entire SELECT
statement.  You're doing the latter.  However, you may be able to
achieve your goal by using the INSERT INTO ... SELECT ... FROM
form of insert.  Check the manual again for the exact syntax.

In any case, you syntax is slightly off because you're specifying
one value list with a single element followed by a value list with
two elements, rather than a single value list with three elements.

--
Paul DuBois, paul@stripped
Thread
SQL - INSERT from existing table with extra values to new tableErik Andersson24 Sep
  • Re: SQL - INSERT from existing table with extra values to newtablePaul DuBois24 Sep
  • Re: SQL - INSERT from existing table with extra values to new tableBob Kline24 Sep