Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Support Forums » ElevateDB SQL » View Thread |
Messages 1 to 5 of 5 total |
INSERT INTO with ORDER BY and RANGE |
Wed, Nov 17 2010 4:16 PM | Permanent Link |
Chris B | Hi guys,
I'm using 2.04B4 and trying to insert/select a range of records into a temporary table The basic query goes like this SELECT SUM(SaleHistory.Quantity) AS ordering_field, Product.Code AS ProductCode FROM Product INNER JOIN SaleHistory ON Product.Code = SaleHistory.Code GROUP BY Product.Code ORDER BY ordering_field DESC RANGE 1 TO 10 However, when inserting into a temporary table I get the following error ElevateDB Error #700 An error was found in the statement at line 9 and column 3 (Expected end of expression but instead found ORDER) CREATE TEMPORARY TABLE MYTEST (ordering_field int, ProductCode int)! INSERT INTO MYTEST (ordering_field, ProductCode) SELECT SUM(SaleHistory.Quantity), Product.Code FROM Product INNER JOIN SaleHistory ON Product.Code = SaleHistory.Code GROUP BY Product.Code ORDER BY ordering_field DESC RANGE 1 TO 10! Using a derived table doesn't cause an error. However, incorrect records are inserted into the temp table INSERT INTO MYTEST (ordering_field, ProductCode) select ordering_field, ProductCode FROM (SELECT SUM(SaleHistory.Quantity) AS ordering_field, Product.Code AS ProductCode FROM Product INNER JOIN SaleHistory ON Product.Code = SaleHistory.Code GROUP BY Product.Code ORDER BY ordering_field DESC RANGE 1 TO 10) TBL234! Any ideas? |
Thu, Nov 18 2010 4:06 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Chris
From memory ElevateDB doesn't support inserting using ORDER BY. I found out when creating in-memory tables. If you want the records on a specific sequence you'll have to create an index afterwards. Roy Lambert [Team Elevate] |
Thu, Nov 18 2010 8:28 AM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Chris,
<< However, when inserting into a temporary table I get the following error ElevateDB Error #700 An error was found in the statement at line 9 and column 3 (Expected end of expression but instead found ORDER) >> You cannot use an ORDER BY clause with an INSERT sub-query. You'll need to create indexes on the temporary table using CREATE INDEX in order to allow for different orders. << Using a derived table doesn't cause an error. However, incorrect records are inserted into the temp table >> What do you mean by "incorrect records" in this context ? Do you mean that it appears like a bug in EDB, or that it doesn't give you the rows that you need ? -- Tim Young Elevate Software www.elevatesoft.com |
Thu, Nov 18 2010 3:31 PM | Permanent Link |
Chris B | <You cannot use an ORDER BY clause with an INSERT sub-query. You'll need to
create indexes on the temporary table using CREATE INDEX in order to allow for different orders.> Fair enough. In this case I'm only interested in selecting the top n records into a temporary table. The ORDER BY was used so the RANGE selects the records I want. Indexing (or having a specific natural order of records in the temp table) was not my concern. <What do you mean by "incorrect records" in this context ? Do you mean that it appears like a bug in EDB, or that it doesn't give you the rows that you need ?> Indeed. It appears to be a bug in EDB. I get a different set of records in the temporary table when doing the derived table insert when compared to using the same select on its own. Attachments: queries.JPG |
Fri, Nov 19 2010 1:53 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Chris,
<< Indeed. It appears to be a bug in EDB. I get a different set of records in the temporary table when doing the derived table insert when compared to using the same select on its own. >> Okay, I'll check this out and see what the issue is. -- Tim Young Elevate Software www.elevatesoft.com |
This web page was last updated on Tuesday, April 30, 2024 at 03:55 PM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |