title: Combining a variable amount of rows into one row?
body: <p>I have two tables: question and answer. </p>
  
  <p>Here is a simplified version of the <strong>question</strong> table's schema:</p>
  
  <pre><code>question_id      integer PRIMARY KEY
  question_title   varchar(250)
  answers_id       SERIAL UNIQUE
  </code></pre>
  
  <p>Here is a simplified version of the <strong>answer</strong> table's schema:</p>
  
  <pre><code>answer_id        integer REFERENCES question (answers_id)
  answer_text      varchar(500)
  is_top_answer    boolean
  </code></pre>
  
  <p>I would like to accomplish three tasks in a single query:</p>
  
  <ol>
  <li>Select a row from the question table based off of a parameter that contains a question_id.</li>
  <li>Join <strong>exactly one</strong> row from the answer table with the row retrieved from the question's table in step 1 of the query where the two following conditions are satisfied by a row in the answer table: 1. the is_top_answer is true and 2. the answer_id equals the answers_id of the row retrieved from the question table in step 1 of the query.</li>
  <li>Join a <strong>variable amount</strong> of rows from the answer table with the row retrieved from the question's table in step 1 of the query where the answer table's answer_id matches the answers_id of the row retrieved from the question table in step 1 of the query.</li>
  </ol>
  
  <p>I have populated the question and answer tables with the following SQL statements: </p>
  
  <pre><code>insert into question values (1, 'Where is the best sushi restaurant?', 10);
  insert into answer values (10, 'In California', 'false');
  insert into answer values (10, 'In Seattle', 'true');
  insert into answer values (10, 'In New York', 'false');
  </code></pre>
  
  <p>If I were to query the question table with a parameter that represents a question_id held in the question table, I would expect the following single row as a result:</p>
  
  <pre><code> question_id |           question_title            | answers_id |   answer_text | is_top_answer  |   answer_text | is_top_answer  |   answer_text | is_top_answer  |
  -------------+-------------------------------------+------------+---------------+----------------+---------------+----------------+---------------+----------------+
             1 | Where is the best sushi restaurant? |         10 | In Seattle    | f              | In California | f              | In New York   | f              |
  </code></pre>
  
  <p>Does anyone have any suggestions for accomplishing this query?</p>