question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MSSQL3Adapter & MSSQL3NAdapter combination of orderby and limitby resulting in a wrong sql query

See original GitHub issue
db.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:closed
  • Created 8 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
niphlodcommented, Mar 8, 2016

@gi0baro : remember this, should be addressed as soon as the new “overhaul” branch gets polished

0reactions
gi0barocommented, Apr 19, 2016

@skoa-h I’m closing this since should be fixed in the current master

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found