orderBy alias
See original GitHub issueI am getting a bit confused as to how to implement the following.
SELECT user.id, max(highscore.amount) AS best
FROM user RIGHT JOIN highscore
ON user.id = highscore.user_id
GROUP BY user.id
ORDER BY best DESC
What’s the equivalent in mammoth notation?
db.select(db.user.id, max(db.highscore.amount).as('best'))
.from(db.user)
.rightJoin(db.highscore)
.on(db.user.id.eq(db.highscore.userId))
.groupBy(db.user.id)
.orderBy(????????)
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
sql - Is it possible to use alias in ORDER BY? - Stack Overflow
A similar question has been answered here. So no you cannot use an alias in that part of the query.
Read more >SQL Tutorial => Order by Alias
Due to logical query processing order, alias can be used in order by. SELECT DisplayName, JoinDate as jd, Reputation as rep FROM Users...
Read more >Using or Not using table alias in Order By clause - Ask TOM
In ORDER BY you can refer to column aliases in the SELECT clause. This is what's happening in query 2. It isn't sorting...
Read more >ORDER BY | InterSystems IRIS Data Platform 2022.2
An ORDER BY clause can specify a table name or table alias as part of the orderItem: SELECT P.Name AS People,E.Name As Employees...
Read more >SQL-Order By - Part -3-Using Alias Name, Sorting ... - YouTube
Order by SQL - Using Alias NameWhy Order By Works With Alias NameSQL Engine - Execution order of Order BYOrder By Using Sorting ......
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 Free
Top 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
Not a problem. It’s a good thing to ask questions.
No, because the implementation only quotes camelCase and reserved keywords. See the second test which does quote the expression alias.
Sorry if I am being picky about this one. Shouldn’t this test actually fail, as the expected SQL string is missing the double quoted alias introduced yesterday?
https://github.com/Ff00ff/mammoth/commit/70e416c83cd7df94c3a4842f77a86c2e66c182ad#diff-dd39016209173bf6d19ea09508619f69e7ef43cb41d53156f395fafae8514100R466