mirror of
https://github.com/doctrine/orm.git
synced 2026-04-30 01:43:20 +02:00
ORDER BY not working with aliases
#5597
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @MaximStrutinskiy on GitHub (Jun 30, 2017).
Originally assigned to: @Ocramius on GitHub.
[symfony3, doctrine orm]
Hi everyone.
I create custom date in ->search() for sorting my items by this field, create name for this:
"(certificate.price) - ((certificate.price / 100) * (certificate.discount)) AS total_price",
but i cant use them in ->andWhere(), i write formula again.
Can i use something this name "total_price" without "(certificate.price) - ((certificate.price / 100) * (certificate.discount))"
@Seb33300 commented on GitHub (Jul 10, 2017):
No, you can't refer to a column alias in the WHERE clause, only in the ORDER BY.
It's a SQL limitation:
https://stackoverflow.com/questions/11182339/reference-alias-calculated-in-select-in-where-clause
@lcobucci commented on GitHub (Aug 21, 2017):
@MaximStrutinskiy you should be able to use aliases In HAVING clause.
@Ocramius commented on GitHub (Aug 21, 2017):
Closing as per @Seb33300's comment.
@yceruto commented on GitHub (Jun 14, 2018):
This issue is confusing, whether the original title as the last one refers to the
ORDER BYclause, but this was closed per @Seb33300's comment, which refers to theWHEREclause.As workaround you can use the field position in
SELECTclause (tried in DBAL layer):Even though MySQL, SQL Server and probably others, support alias in order by clause.