title: Grouping Data from Two tables in MySQL
body: <p>I have 2 tables, <code>posts</code> and <code>posts_flags</code>. <code>posts</code> contains the rows of posts made by the users. Now, if some post gets reported, users have the ability to report the post, thus creating a flag in the <code>posts_flags</code> table. So basically, <code>posts_flags</code> can have multiple flags for the same post.</p>
  
  <p>Now, what I'm trying to do is get the <code>posts</code> rows from the <code>posts</code> table and add a column to show which one has been flagged. To get that column, I am trying to do an INNER JOIN with <code>posts</code> and <code>posts_flags</code> using the <code>post_id</code>. However, I hit an issue now because the <code>posts_flags</code> can have multiple rows for the same post.</p>
  
  <p>How can I get those data? Below is a sample structure of my tables and what I'm trying to achieve.</p>
  
  <p><strong>posts table</strong></p>
  
  <pre><code>| post_id | post_title | post_body |
  |    1    |   title a  | something |
  |    2    |   title b  | something |
  |    3    |   title c  | something |
  </code></pre>
  
  <p><strong>posts_flags table</strong></p>
  
  <pre><code>| post_id | user_id |
  |    1    |   4     | 
  |    1    |   5     | 
  |    2    |   5     | 
  
  </code></pre>
  
  <p><strong>What I am trying to achieve</strong></p>
  
  <pre><code>|  post_id | post_title | post_body | flagged
  |    1     | title a    | something |   1
  |    2     | title b    | something |   1
  |    3     | title c    | something |   0
  </code></pre>
  
  <p>Thank you!</p>