ZF-11821: There still seams to be a problem with Order by and Limit when useing 2 arguments with DESC

Issue Type: Bug Created: 2011-10-14T08:33:16.000+0000 Last Updated: 2012-03-20T23:53:41.000+0000 Status: Closed Fix version(s): Reporter: Johan Carstensen (johancarstensen) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Db_Select

  • Zend_Db
  • zf-caretaker-adamlundrigan

Related issues: Attachments:


I have read the issues previously reported about "Zend_Db_Select problem with 2 order by and limit" and other bugs about the same thing. I have recently come to the conclusion that the problem with this issue is not fixed entirely in version 1.10.8 of ZendFramework.

The issiue is only arrising when using MSSQL Servers. I think it has something to do with that sends uses TOP command. This is the wrong way to do limit in a MSSQL database.

I would recommend using something like this in MSSQL instead of using MSSQL Top command when doing the limit:

select * from (select Row_Number() over (order by c.dateno1) as RowIndex, * from mytable AS c WHERE = 4) as Sub Where Sub.RowIndex >= 8 and Sub.RowIndex < 16;

I have problems when running a code like this:

$select = $this->select() ->from($this->_name) ->where('id=?', $id) ->where('status!=?', 'AAAA') ->where('status!=?', 'BBBB') ->order(array('dateno1 DESC', 'dateno2 DESC')) ->limit($nbrs,$start);

The ordering of the resultset comes in the wrong order.

Removing the secound agument is wrong way to go but fixes this issue for us right now until this is resolved in ZendFramework.

$select = $this->select() ->from($this->_name) ->where('id=?', $id) ->where('status!=?', 'AAAA') ->where('status!=?', 'BBBB') ->order(array('dateno1 DESC')) ->limit($nbrs,$start);


Posted by Adam Lundrigan (adamlundrigan) on 2011-10-14T16:05:33.000+0000

Could you run your code against the latest ZF release (1.11.11) to see if the problem still persists there?

If so, could you please provide some additional information to explain the problem you are having? Ideally a snippet of code where the query is built plus the database schema and a few example rows which will illustrate the case where rows are returned in the wrong order.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.