title: postgreSQL join and embed array of records
body: <p>I have two tables. One is <strong>events</strong> and the other is <strong>people</strong>. They look like this:</p>
  
  <pre><code>    events          | data_type 
  --------------------+-----------
   event_id           | integer
   start              | TIMESTAMP WITH TIME ZONE
   end                | TIMESTAMP WITH TIME ZONE
  
  
   people          | data_type 
  --------------------+-----------
  people_id           | integer
  name                | TEXT
  event_id            | integer
  </code></pre>
  
  <p>I'd like to query a single event for event information, but I would also like to get a list of guests (tied to people) who are going to be at an event. </p>
  
  <p>The output I am ultimately looking for looks like this (transformed to json):</p>
  
  <pre><code>{
    "event_id": 1,
    "start": Fri, 05 Aug 2016 21:18:38 GMT,
    "end": Fri, 05 Aug 2016 21:18:38 GMT,
    "guests": [
              {"name": "John", event_id: 1}, //record from people table
              {"name": "Sarah", event_id: 1} 
    ]
  }
  </code></pre>
  
  <p>How can I elegantly perform a join in Postgresql that will retrieve all the associated people records I have?</p>
  
  <p>So far I have the following query:</p>
  
  <pre><code>SELECT
  *
  FROM events, people
  WHERE events.event_id = people.event_id 
  </code></pre>