title: SQL - Retrieving latest message for a CASE WHEN statement
body: <p>I have a problem here trying to get one of my <code>CASE WHEN</code> statement to query each row for something called <code>is_op</code> as it's returning the same number for all rows. Here is the code:</p>
  
  <pre><code>SELECT `mid`, `message`, `created_at`, 
  CASE WHEN (SELECT `uid` FROM `bulletin_message` WHERE `bid` = 1 ORDER BY `mid` ASC LIMIT 1) = 5 THEN 1 ELSE 0 END AS `is_op`, 
  CASE WHEN `bulletin_message`.`uid` = 5 THEN 1 ELSE 0 END AS `is_me` 
  FROM`bulletin_message`
  WHERE `bid` = 1 
  GROUP BY `mid` 
  ORDER BY `mid` ASC
  </code></pre>
  
  <p>As you can see I'm trying to select messages with the condition <code>bid</code> must equal to 1 and <code>uid</code> must equal to 5. While <code>is_me</code> returns the correct value for each row, <code>is_op</code> isn't reflecting the correct value for all the rows at all. It displays <code>1</code> at the result of the statement, rather than showing if a user is an OP or not based on the oldest value of <code>mid</code> or <code>created_at</code>. I don't think I am correctly querying each row like <code>is_me</code> statement.</p>
  
  <p>This is all the data of the table:</p>
  
  <pre><code>mid = message uid; bid = bulletin/thread uid; uid = user uid
  
  |   mid  |   bid  |  uid   | message | created_at |
  ---------------------------------------------------
  |      3 |    1   |      5 |   ...   |      ...   |
  |      5 |    1   |      6 |   ...   |      ...   |
  |      6 |    2   |      7 |   ...   |      ...   |
  |      9 |    1   |      5 |   ...   |      ...   |
  |     10 |    1   |      7 |   ...   |      ...   |
  |     11 |    1   |      6 |   ...   |      ...   |
  </code></pre>
  
  <p>What can be done to improve this line of code so that it can query each row? Thank you!</p>
  
  <p>Edit: OP is Original Poster, sorry for not clarifying that! It's usually the person who post the first in each <code>bid</code>.</p>