MSSQL3Adapter & MSSQL3NAdapter combination of orderby and limitby resulting in a wrong sql query
See original GitHub issuedb.define_table('tag', Field('title', 'string'),)
tags = db(db.tag.id > 0).select(
db.tag.id,
db.tag.title,
orderby=db.tag.title|db.tag.id,
limitby=(1,40),
)
print db._lastsql
SELECT f_0, f_1 FROM (SELECT ROW_NUMBER() OVER (ORDER BY tag.id, tag.title) AS w_row, tag.id AS f_0, tag.title AS f_1 FROM tag WHERE (tag.id > 0) ) TMP WHERE w_row BETWEEN 2 AND 40;
in OVER (ORDER BY tag.id, tag.title) the order of the statements is wrong, it seems id is always first. I found the bug because SQLFORM.grid messed up the column sorting in pages > 1.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
OrderBy clause is resulting different result sets when order ...
SQL Server (or any RDBMS) does not guarantee results to be returned in a particular order if no ORDER BY clause was specified....
Read more >SQL Order by Clause overview and examples
This article will cover the SQL ORDER BY clause including syntax, usage scenarios to sort out results in a Select statement.
Read more >Using the WHERE and ORDER BY Clauses in SQL
SQL uses the ORDER BY statement to sort records. You can sort records in ascending or descending order, and you can sort records...
Read more >SELECT - ORDER BY Clause (Transact-SQL) - Microsoft Learn
Use this clause to: Order the result set of a query by the specified column list and, optionally, limit the rows returned to...
Read more >SQL ORDER BY Keyword - W3Schools
The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@gi0baro : remember this, should be addressed as soon as the new “overhaul” branch gets polished
@skoa-h I’m closing this since should be fixed in the current master