ClanCats / Hydrahon

🐉 Fast & standalone PHP MySQL Query Builder library.
https://clancats.io/hydrahon/master/
MIT License
278 stars 58 forks source link

how to do GROUP_CONCAT using Hydrahon #42

Closed dht20 closed 4 years ago

dht20 commented 4 years ago

im trying to do

SELECT id , GROUP_CONCAT(name) like this select("id, GROUP_CONCAT(name) ")

but i getting problemes , how can i do it properly?

mario-deluna commented 4 years ago

Hello there,

You can use the Func or Expression object.

use ClanCats\Hydrahon\Query\Sql\Func;

$h
    ->table('stats')
    ->select(['id', new Func('GROUP_CONCAT', 'name')])
    ->execute();

Result:

select `id`, GROUP_CONCAT(`name`) from `stats`