Hi!

>>>>> "Lance" == Lance Lovette <[EMAIL PROTECTED]> writes:

Lance> The following CREATE TABLE statements seem straight forward but they all
Lance> fail. Can someone explain why they fail and what I can do to get rid of the
Lance> "Duplicate column name" errors?

mysql> CREATE TEMPORARY TABLE User2 (UserID int(11)) SELECT UserID FROM
Lance> User;

Lance> ERROR 1060: Duplicate column name 'UserID'

The above is an correct error message.

What you are trying to do is the following:

CREATE TEMPORARY TABLE User2 (UserID int(11) not null, UserID int(11)) SELECT UserID 
FROM User;

This is because all columns from the SELECT is automaticly insert into
the table with the given column and type taken from the corresponding
column in the select statement.

This makes it trivial to quickly do things like:

CREATE TEMPORARY TABLE test (primary key (id)) SELECT ...many-fields....

Which will create a temporary table with all columns and have a
primary key on the column named 'id'.

Regards,
Monty


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to