# SQL Error \[HY000\]: ORDER BY is mandated in the OVER clause for the function row\_number.

**URL:** <https://community.cdata.com/t/sql-error-hy000-order-by-is-mandated-in-the-over-clause-for-the-function-row-number/379>\
**Category:** CData Drivers\
**Tags:** sql, question, driver, xbase\
**Created:** [September 6, 2023, 1:15pm UTC](https://community.cdata.com/t/sql-error-hy000-order-by-is-mandated-in-the-over-clause-for-the-function-row-number/379 "2023-09-06T13:15:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmarkmurphy](https://avatars.discourse-cdn.com/v4/letter/j/f05b48/32.png) [@jmarkmurphy](https://community.cdata.com/u/jmarkmurphy)\
**Post date:** [September 6, 2023, 1:15pm UTC](https://community.cdata.com/t/sql-error-hy000-order-by-is-mandated-in-the-over-clause-for-the-function-row-number/379/1 "2023-09-06T13:15:12Z")

</div>

I am using the 2023 xBase driver in dBeaver, and receiving this error:

SQL Error [HY000]: ORDER BY is mandated in the OVER clause for the function row\_number.

The Query is:

`select distinct       'BNK' swityp,       cast(c.cbank_acct as varchar) oldkey,       row_number () over (order by g.cid) newkey,       '' del,       g.cgroup_cod,       g.acct_no,       g.acct_descr,       g.active,       g.cidfrom checkreg cjoin glacct g on g.cid = c.cbank_acctorder by g.cid`

As you can see I have an ORDER BY in the OVER clause. BTW, changing it to upper case has no&nbsp;effect. What am I missing? Does xBase only partially support row\_number? Is there any documentation on the xBase driver and which syntax it supports?

---

<div class="post-metadata">

**Author:** ![Ethem\_Q](https://sea3.discourse-cdn.com/cdata/user_avatar/community.cdata.com/ethem_q/32/1997_2.png) [@Ethem\_Q](https://community.cdata.com/u/Ethem_Q)\
**Post date:** [September 8, 2023, 3:46pm UTC](https://community.cdata.com/t/sql-error-hy000-order-by-is-mandated-in-the-over-clause-for-the-function-row-number/379/2 "2023-09-08T15:46:41Z")

</div>

Thank you for posting your issue here. From a first look, the syntax of the query you are executing is quite correct so there should not be a reason for you to see the error. I suspect there might be an issue on how the query is being processed under the hood but in order to verify that we will need our engineering team to make a more in-depth investigation.

In the meantime, you might want to use the following query as a workaround:

SELECT DISTINCT \* FROM ( SELECT  
&nbsp; &nbsp; &nbsp; ‘BNK’ swityp,  
&nbsp; &nbsp; &nbsp; &nbsp;CAST(c.cbank\_acct as varchar) oldkey,  
&nbsp; &nbsp; &nbsp; &nbsp;ROW\_NUMBER () OVER (ORDER BY g.cid) newkey,  
&nbsp; &nbsp; &nbsp; &nbsp;‘’ del,  
&nbsp; &nbsp; &nbsp; &nbsp;g.cgroup\_cod,  
&nbsp; &nbsp; &nbsp; &nbsp;g.acct\_no,  
&nbsp; &nbsp; &nbsp; &nbsp;g.acct\_descr,  
&nbsp; &nbsp; &nbsp; &nbsp;g.active,  
&nbsp; &nbsp; &nbsp; &nbsp;g.cid  
FROM checkreg c  
JOIN glacct g on g.cid = c.cbank\_acct  
ORDER BY g.cid)

Let me know if that works for you.

---

<div class="post-metadata">

**Author:** ![jmarkmurphy](https://avatars.discourse-cdn.com/v4/letter/j/f05b48/32.png) [@jmarkmurphy](https://community.cdata.com/u/jmarkmurphy)\
**Post date:** [September 8, 2023, 4:45pm UTC](https://community.cdata.com/t/sql-error-hy000-order-by-is-mandated-in-the-over-clause-for-the-function-row-number/379/3 "2023-09-08T16:45:24Z")

</div>

This does work. I did not even consider that the distinct was the culprit. thanks for the workaround. A note for the engineering teem, it isn’t just row\_number() that fails like this, rank() and dense\_rank() have the same issue, and workaround.

---

<div class="post-metadata">

**Author:** ![Ethem\_Q](https://sea3.discourse-cdn.com/cdata/user_avatar/community.cdata.com/ethem_q/32/1997_2.png) [@Ethem\_Q](https://community.cdata.com/u/Ethem_Q)\
**Post date:** [October 17, 2023, 3:23pm UTC](https://community.cdata.com/t/sql-error-hy000-order-by-is-mandated-in-the-over-clause-for-the-function-row-number/379/4 "2023-10-17T15:23:12Z")

</div>

I wanted to update this thread as the engineering team has implemented a fix for the issue that was reported here.

If you want to get an updated version of the JDBC driver for xBase feel free to reach our support team out at [support@cdata.com](mailto:support@cdata.com) or submit a support ticket here [https://www.cdata.com/support/submit.aspx](https://www.cdata.com/support/submit.aspx)
