Last active
August 29, 2015 14:18
-
-
Save settermjd/3360ccabb2b761a6ee11 to your computer and use it in GitHub Desktop.
Joining equal values, that were returned from a database
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
/** | |
* The following code builds this query: | |
* SELECT `amount` | |
* , GROUP_CONCAT(`Name` SEPARATOR ', ') AS `name` | |
* FROM `table` | |
* GROUP BY `amount` | |
* ORDER BY `amount` DESC | |
* LIMIT 0, 3 | |
*/ | |
public function getSome() | |
{ | |
$select = $this->tableGateway->getSql()->select(); | |
$select->columns([ | |
'amount', | |
'name' => new \Zend\Db\Sql\Expression("GROUP_CONCAT(Name SEPARATOR ', ')") | |
]) | |
->order('amount DESC') | |
->group('amount') | |
->limit(3); | |
return $this->tableGateway->selectWith($select); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment