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.
http://www.mysql.com/Manual_chapter/manual_Reference.html#INSERT
--
Paul DuBois, paul@stripped