Frage

I cant realize whats wrong with my query (Firebird SQL):

select max(column1) from (select first 100 column1 from table1 where column1 > 0) p

Error message:

SQL Message : -104
Invalid token
Message: isc_dsql_prepare failed
SQL Message : -104
Invalid token
Engine Code    : 335544569
Engine Message :
Dynamic SQL Error
SQL error code = -104
Token unknown 

Any help is appreciated!

War es hilfreich?

Lösung 3

SQL does not have FIRST keyword it uses TOP keyword. Full explanation here

http://technet.microsoft.com/en-us/library/ms189463.aspx

Firebird:

"In MS SQL 7 and above, the SELECT clause can take a TOP specifier to limit the number of rows returned. This feature is currently under development for the Firebird engine."

http://www.firebirdsql.org/manual/migration-mssql-syntax.html#migration-mssql-sql-cursors

Andere Tipps

Nested SELECT queries ("SELECT from SELECT") use derived tables, which are only supported in Firebird 2.0 and above.

However, since Firebird 1.5 allows SELECT statements to appear in the WHERE clause, your query can be rewritten as:

select max(column1) from table1
where column1 in (
    select first 100 column1 from table1
    where column1 > 0
)

This is a perfect SQL query, so it should work perfectly. I have tested something the same and it works. My guess is that the data type does not allow the comparison or max to be used. (e.g. column1 is a varchar or something non integer compatible)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top