Distinct in ORM select expression

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • czcpf
    Senior Member
    • Aug 2022
    • 160

    Distinct in ORM select expression

    I see we have in QueryBuilder or SelectBuilder etc.

    PHP Code:
    ->select([...])
    ->distinct() 
    
    to make the params in select distinct in the query. However, how does one accomplish the following in ORM fashion ?

    SQL/MYSQL QUERY EXAMPLE

    SELECT DISTINCT rml.id AS locationId, COUNT(DISTINCT rm.id)
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    Better to use SELECT COUNT(alias.id) FROM (SELECT DISTINCT id FROM `my_table` ... ) AS `alias`

    Like so https://github.com/espocrm/espocrm/b...apper.php#L251

    Or use the mapper's count method.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    Working...