Left join query between two custom tables Hi I'm trying to create a join query between two custom tables. One is publish_options with a pubid as the primary key. The other is publish_options_bundles with a referring field pubid to the first table.

The problem I'm having is that the results returned are as such:

Array
(
    [0] =&gt; stdClass Object
        (
            [__CLASS__] =&gt; stdClass
            [pubid] =&gt; 51
            [title] =&gt; Promote to blog
            [created] =&gt; 1549262900
            [modified] =&gt; 1549262900
            [bundle] =&gt; article
        )

    [1] =&gt; stdClass Object
        (
            [__CLASS__] =&gt; stdClass
            [pubid] =&gt; 51
            [title] =&gt; Promote to blog
            [created] =&gt; 1549262900
            [modified] =&gt; 1549262900
            [bundle] =&gt; gallery
        )

    [2] =&gt; stdClass Object
        (
            [__CLASS__] =&gt; stdClass
            [pubid] =&gt; 51
            [title] =&gt; Promote to blog
            [created] =&gt; 1549262900
            [modified] =&gt; 1549262900
            [bundle] =&gt; page
        )

)


I would like it to return like:

(
  [__CLASS__] =&gt; stdClass
  [pubid] =&gt; 51
  [title] =&gt; Promote to blog
  [created] =&gt; 1549262900
  [modified] =&gt; 1549262900
  [bundles] =&gt; [
    page,
    article,
    gallery,
  ]
)


The code I've come with is below.

$query = $this-&gt;connection-&gt;select('publishing_options', 'po')
      -&gt;fields('po')
      -&gt;condition('po.pubid', $id);
    $query-&gt;leftJoin('publishing_options_bundles', 'pob', 'po.pubid = pob.pubid');
    $query-&gt;fields('pob', ['bundle']);

    $result = $query-&gt;execute()-&gt;fetchAll();


Any help would be greatly appreciated as I am completely stumped now.

Thank you in advance.
I found the way to do what I wanted.

The modified query:

    $query = $this-&gt;connection-&gt;select('publishing_options', 'po')
      -&gt;fields('po')
      -&gt;condition('po.pubid', $id);
    $query-&gt;join('publishing_options_bundles', 'pob', 'po.pubid = pob.pubid');
    $query-&gt;addExpression('GROUP_CONCAT(DISTINCT pob.bundle)', 'bundles');
    $query-&gt;groupBy(['po.pubid']);
    $result = $query-&gt;execute()-&gt;fetch();


I added the groupBy() methond and the addExpression() method with a GROUP_CONCAT

The results:

stdClass Object
(
    [__CLASS__] =&gt; stdClass
    [pubid] =&gt; 51
    [title] =&gt; Promote to blog
    [created] =&gt; 1549262900
    [modified] =&gt; 1549262900
    [bundles] =&gt; article,gallery,page
)