on 2011 Jul 11 6:18 PM
We just upgraded from SQL Anywhere 9.0.2 to ver 11.0.1 and all the views in our database are not sorting. It is ignoring the Order by clause. Is there some database setting that I missed which is causing the dbms to ignor the sorting built into the view's SQL statement?
Request clarification before answering.
To add to Thomas's answer:
The 12.0.1 docs point out the following to the usage of ORDER BY in a view definition:
The semantics of queries dictates that the order of the rows returned is undefined unless the query combines an ORDER BY clause with a TOP or FIRST clause in the SELECT statement.
If an ORDER BY clause is specified along with either a TOP or FIRST clause, then the query returns the top n rows, or the first row, respectively.
I.e. using ORDER BY is quite useless (and according to Thomas, possibly bad w.r.t. performance) unless you want to use a TOP n / FIRST / LIMIT clause. To get an ordered result set, you will have to use
select * from myView order by myColumnList
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The CREATE VIEW Help is clear about this
..., using a SELECT with an ORDER BY clause does affect the results of a view definition.
I have seen in SA 9 that I could create a View with order by but it was always a performance killer.
HTH
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
76 | |
30 | |
8 | |
8 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.