List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:September 10 1999 2:40pm
Subject:Re: Need Help with INSERT
View as plain text  
At 3:07 PM +0100 9/10/99, rekcah wrote:
>I'm trying to insert into a table "track" but i want it to take some 
>of the data from another table "customer"
>here is an example of what i tryed
>INSERT INTO track (file_no,cid,file_name,pdf_file,comments) values 
>('1111', 'SELECT (cid) FROM customer where customer_name = "John 
>Doe"', 'Part A', 'file.pdf', 'Comments blah blah');
>cid came out as 0 istead of 2 which would have been John Doe's cid number.
>Maybe what i'm trying is impossible or maybe i 'm going about it all wrong.

You're trying to insert a literal string consisting of the text
'SELECT (cid) FROM customer where customer_name = "John Doe"'
into a numeric field.  MySQL performs a string-to-number conversion,
and since the string doesn't look like a number, you get a zero.

In any case, you can't put a SELECT statement where you're trying to.
You can select the value you want first in a SELECT statement,
then use the value in an INSERT statement.

Alternatively, you may be able to arrange what you want using
MySQL's INSERT INTO ... SELECT ... FROM ... statement, which looks
as though it may accomplish your goal.

Paul DuBois, paul@stripped
Need Help with INSERTrekcah10 Sep
  • Re: Need Help with INSERTPaul DuBois10 Sep
RE: Need Help with INSERTClinton Gormley10 Sep
  • Alter column to autoincrementmtweito10 Sep
RE: Alter column to autoincrementJohn Millaway10 Sep