Hi.

On Wed, Jun 13, 2001 at 01:47:53PM +0200, [EMAIL PROTECTED] wrote:
> Hi
> 
> Sorry for this question but this is my first shot at this list.
> 
> I have created a table that contains the following:
> CREATE TABLE liggare (raknare INT(10) UNSIGNED ZEROFILL DEFAULT '0000000000' NOT 
>NULL,
> 
>  projno INT(5) UNSIGNED ZEROFILL DEFAULT '10000' NOT NULL,
> 
>  ritnummer INT(8) UNSIGNED ZEROFILL DEFAULT '' NOT NULL,
> 
> utgava INT(2) UNSIGNED ZEROFILL DEFAULT '01' NOT NULL,
> 
> besk CHAR(50) DEFAULT '' NOT NULL,
> 
> kund CHAR(50) DEFAULT '' NOT NULL,
> 
> utdatum CHAR(20) DEFAULT '' NOT NULL, utsign CHAR(5) DEFAULT '' NOT NULL,
> 
> ritad CHAR(5) DEFAULT '' NOT NULL, operativ CHAR(10) DEFAULT 'Genius 14' NOT NULL,
> 
> sokvag CHAR(100) DEFAULT '' NOT NULL,
> 
> PRIMARY KEY(raknare)); 
> 
> Now I try to create another table with colums from the first table like this:
> 
> CREATE TABLE godkann (raknare, projno) AS (SELECT raknare, projno FROM liggare);
> 
> And I got this error:
> 
> ERROR 1064: You have an error in your SQL syntax near ' projno) AS (SELECT raknare, 
>projno FROM liggare)' at line 1

You have to provide the column type with the name, i.e.

CREATE TABLE godkann (
  raknare INT(10) UNSIGNED ZEROFILL DEFAULT '0000000000' NOT NULL,
  projno INT(5) UNSIGNED ZEROFILL DEFAULT '10000' NOT NULL
)
AS SELECT ...

But the nice thing is: you probably don't need the column
specification at all, because it is copied from the columns in the
SELECT. So just try

CREATE TABLE godkann AS SELECT raknare, projno FROM liggare

and see if you are satisfied with the result.

Next, I am not sure, if the parenthesis around the SELECT are allowed
with MySQL, but at least, they are not necessary... If you get an
error you now know what to do. :-)

Bye,

        Benjamin.


PS: I did not check for the rest of the CREATE ... SELECT syntax
(e.g. I am not positive that 'AS' is required/allowed/what else.

---------------------------------------------------------------------
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