title: How do I SELECT data from child table in PostgreSQL?
body: <p>In PostgreSQL 9.4, how do I retrieve json object like this:</p>
  
  <pre><code>parentTableFirstProp: 'string',
  parentToChildReference: [
      {childTableFirstProp: 'another string'},
      {childTableFirstProp: 'yet another string'}
  }]
  </code></pre>
  
  <p>instead of this:</p>
  
  <pre><code>[{
      parentTableFirstProp: 'string',
      childTableFirstProp: 'another string',
  },{
      parentTableFirstProp: 'string',
      childTableFirstProp: 'yet another string'
  }]
  </code></pre>
  
  <p>Do I always have to make 2 select queries, and insert one to another by usage of aliases?
  Could you just show an example: how do you <code>SELECT</code> parent table along with it's children?</p>
  
  <p><strong>UPD 1</strong>
  this:</p>
  
  <pre><code>SELECT
  "public"."ParentTable".*,
  "public"."ChildTable".*
  FROM
  "public"."ParentTable"
  RIGHT JOIN "public"."ChildTable"
  ON "public"."ParentTable"."childReference"
  </code></pre>
  
  <p>returns this:</p>
  
  <pre><code>[{
          parentTableFirstProp: 'string',
          childTableFirstProp: 'another string',
      },{
          parentTableFirstProp: 'string',
          childTableFirstProp: 'yet another string'
      }]
  </code></pre>
  
  <p><strong>UPD 2</strong><br>
  Create tables statements:</p>
  
  <pre><code>CREATE TABLE "public"."ParentTable" (
      "id" varchar(36) NOT NULL COLLATE "default",
      "parentTableFirstProp" varchar(100) NOT NULL COLLATE "default",
      "parentToChildReference" varchar COLLATE "default"
  )
  
  CREATE TABLE "public"."ChildTable" (
      "id" varchar(36) NOT NULL COLLATE "default"
      "childTableFirstProp" varchar(100) NOT NULL COLLATE "default",
  )
  </code></pre>