Laravel Union操作后排序错误的问题 Fix the wrong order after using union method in Laravel query

解决方法,在两个子查询中分别加上limit即可。可以使用较大的数确保所有记录返回。

The solution is to use the limit method on the two subqueries. You can use a larger number to ensure that all records are returned.

 

《Laravel Union操作后排序错误的问题 Fix the wrong order after using union method in Laravel query》上有2条评论

  1. Getting all the rows and counting total is memory inefficient. So I used following approach to get total count. together and got right result under laravel 5.7.20. This will be better than merging collections then paginate which will not work on big amount of data.

发表评论

电子邮件地址不会被公开。 必填项已用*标注