Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SYBASE ASA :: ORDER BY in sub-query !!

2 views
Skip to first unread message

Chithu

unread,
Jul 15, 2002, 7:52:10 AM7/15/02
to
Hi ..,

Sybase ASA - Adaptive Server Anywhere :: 8.0.1.2600
JDBC Driver Version :: jConnect (TM) for JDBC(TM)/5.2(Build
20693)/P/EBF9007
/JDK12/Mon Apr 3 12:33:02 2000

I have a requirement to select rows from a table within the
specified range using Sybase ASA.
For example i need to select rows from 15 to 22 out of 26
rows. I need this after sorting the rows in the table in the
descending order.

Assume that, Values from a to z (26 rows) in the table
TestTable . I want to sort this in the descending order and then
retrieve rows from 15 to 22 (l to e).

I used the following query,

select * from (select top 8 * from (select top 22 * from
TestTable order by Name DESC) as T1 order by Name ASC) as T2 order by
Name DESC)

com.sybase.jdbc2.jdbc.SybSQLException: ASA Error -131: Syntax error
near 'order' on line 1
at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2415)
at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:1851)
at com.sybase.jdbc2.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:201)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:182)
at com.sybase.jdbc2.jdbc.SybStatement.queryLoop(SybStatement.java:1401)
at com.sybase.jdbc2.jdbc.SybStatement.executeQuery(SybStatement.java:1386)
at com.sybase.jdbc2.jdbc.SybStatement.executeQuery(SybStatement.java:399)
...
...

Is order by in inner query not supported one..?? If so, how to
achieve my requirement..??

The inner query "select top 22 * from TestTable order by Name
DESC" is working fine.

Any help will be appreciated.

NOTE : I've refered some posts , Subject: Help - SQL not working
correctly,
In that , "ORDER BY is not currently supported in subqueries" --
Robert Waywell, Certified SQL Anywhere Associate, Sybase's iAnywhere
Solutions.
Is this fixed?? Or any work around to this??

Thanks in advance.

Regards,
Chithuu..

--CELKO--

unread,
Jul 15, 2002, 8:07:12 PM7/15/02
to
>> For example I need to select rows from 15 to 22 out of 26 rows. I

need this after sorting the rows in the table in the descending order.
<<

You missed the whole point of SQL. Tables are sets; sets have no
ordering. Sequential files are ordered. Ordering occurs when the
result set is passed to the host program via a cursor, not in the
database. You are looking for proprietary "extensions" (actually
"regressions") so you can avoid learning SQL and the relational model.

I am willing to bet money that your schema is not even normalized.
Please stop what you are doign and get some help with the schema
design,a nd some SQL training -- it will really help.

0 new messages