Last active
January 27, 2016 22:27
-
-
Save ABM-Dan/108239bb0c8afe1b7579 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Trying to emulate | |
// SELECT l.*, MAX(s.sale_ts) FROM location AS `l` LEFT JOIN sales AS `s` ON l.id = s.location_id GROUP BY(s.location_id); | |
// But the group selects the last result. | |
$qb = $this->createQueryBuilder('l') | |
->leftJoin('l.sales', 's') | |
->where('l.is_active = 1') | |
->orderBy('l.id', 'ASC') | |
->addOrderBy('s.sale_ts', 'DESC') | |
->groupBy('l.id'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment