Cannot use SELECT in INSERT statement (book says I can!)

Cannot use SELECT in INSERT statement (book says I can!)

am 18.03.2003 08:39:07 von Hal Vaughan

I'm using Sam's "Teach Yourself MySQL in 21 Days" as an introductory tuto=
rial=20
and guide book. I've had several problems with this (actually a lot -- I=
'm=20
going out to buy a copy of the O'Reilly book on the mysql.com website whe=
n my=20
check comes in later this week).

It has an example in the book like this:

INSERT INTO Shipper_Info
(Customer_Name, Address, City, Zip)
VALUES
SELECT CAT(First_Name + " " + Last_Name)
AS Name, Address, City, Zip
FROM Customers
WHERE
State =3D "MD";

I don't have the tables set up, so I haven't tried this letter for letter=
, but=20
I am trying the following:

INSERT INTO Distro (Class) VALUES SELECT Class FROM xfer2;

(xfer2 is a temp table while I'm doing transfers). I had a WHERE clause =
on=20
the end (WHERE Class LIKE "%"), just to see if it was necessary, but it h=
ad=20
no effect.

Whenever I run this line, I get an error (error 1064 You have an error in=
your=20
SQL syntax near 'SELECT Class FROM xfer2 at Line 1;)

I've noticed when I get an error message that usually the error is at the=
=20
start of the quoted section of a line.

So what am I doing wrong and why can't I use SELECT in an INSERT statemen=
t? =20
It seems to be, other than adding CAT to combine 2 fields, and using a WH=
ERE=20
clause, that I'm doing the same thing as in the example, but no matter wh=
at I=20
do or how I re-arrange things, it won't work.

What am I doing wrong?

Thanks!

Hal

------------------------------------------------------------ ---------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail msql-mysql-modules-thread2086@lists.mysql.com

To unsubscribe, send a message to the address shown in the
List-Unsubscribe header of this message. If you cannot see it,
e-mail msql-mysql-modules-unsubscribe@lists.mysql.com instead.