OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
RE: insert-select-statement doesn't take order-by-clause

From: Knappke, Christian (christian.knappkesap.com)
Date: Fri Jan 23 2004 - 02:07:41 CST


Sven wrote:
> i tried to insert something like
>
> INSERT INTO table1(col2)
> SELECT col1 FROM table2
> ORDER BY col1
>
> but according to the grammer ORDER BY is not allowed.
> well, you could say that the order of the rows doesn't matter, but it
> does. Imagine you've got a SERIAL-column in table1.

No, it does not matter. If the field you insert is the primary key, the table *is* already sorted. If you need a certain relation between a SERIAL column and COL2, then your application is responsible to calculate it. You *can* insert SERIAL values, it is handled like a normal INT field. You can even fill in gaps in the sequence unless you violate any constraint.

If you plan to SELECT ... ORDER BY COL2, then you might consider to create an index on COL2.

Regards
Christian

--
#include <std_disclaimer.h>
/* The opinions stated above are my own and not
   necessarily those of my employer. */

--
MaxDB Discussion Mailing List
For list archives: http://lists.mysql.com/maxdb