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.

I 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:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
martijndehcommented, Jan 14, 2022

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.

0reactions
AuspeXeucommented, Jan 14, 2022

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

Read more comments on GitHub >

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

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