title: MYSQL Query - Select posts and like counts for each post
body: <p>I am trying to get all the posts that belong to a certain user and then the like counts for each of those posts.</p>
  
  <p>Here I get the all the posts that belong to a certain user:</p>
  
  <pre><code>SELECT Posts.id,
  Posts.uuid,
      Posts.caption,
      Posts.path,
      Posts.date,
      USERS.id,
      USERS.username,
      USERS.fullname,
      USERS.profileImage
      FROM A.Posts JOIN A.USERS ON
      Posts.id = 145 AND USERS.id = 145 ORDER by date DESC
      LIMIT 0, 5
  </code></pre>
  
  <p>And here is how I query the likes for each post:</p>
  
  <pre><code>SELECT COUNT(uuidPost)
   FROM Activity
   WHERE type =  "like" AND uuidPost = "FA4C8196-CEA3-4373-94B2-59F387BB1906"
  </code></pre>
  
  <p>Not sure how to combine them?</p>
  
  <p>If anyone can help or give me tips on the queries, I'd appreciate all the help!</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>SELECT Posts.id,
      Posts.uuid,
      Posts.caption,
      Posts.path,
      Posts.date,
      USERS.id,
      USERS.username,
      USERS.fullname,
      USERS.profileImage,
      coalesce(A.LikeCNT,0),
  IF( A.uuidPost IS NOT NULL , 1, 0 ) AS CurrentUser
  FROM Posts 
  INNER JOIN USERS 
  ON Posts.id = 145 
  AND USERS.id = 145
  LEFT JOIN (SELECT COUNT(A.uuidPost) LikeCNT, A.UUIDPost, A.id
  FROM Activity A
  WHERE type = 'like' 
  GROUP BY A.UUIDPOST) A
  on A.UUIDPost=Posts.uuid
  AND A.id = Posts.id
  WHERE Posts.id = 145
  ORDER BY date DESC
  LIMIT 0, 5
  </code></pre>