title: How can I limit the selection of items with SQL per value?
body: <p>Ok, so I have this private messaging system I'm working on, and here's kind of how it's organized</p>
  
  <pre><code>ID From-ID To-ID Message Thread
  1 0 1 "blah blah blah" 1
  2 0 1 "blah blah blah, blah!" 1
  3 0 3 "hey &lt;3&gt;, how are you? Signed, &lt;0&gt;" 2
  </code></pre>
  
  <p>The way it's like this is so that you can have multiple messages in a thread, so you can reply.</p>
  
  <p>Then on the left side of my private messages page, you can select which thread to look at.</p>
  
  <p>So, it'll be a button that says the sender's name, so I used this SQL:</p>
  
  <pre><code>mysql_query("SELECT * FROM pms WHERE to-id='".$_SESSION['id']."' ORDER BY id ASC");
  </code></pre>
  
  <p>But, I want it to be something like (pseudo-code)</p>
  
  <pre><code>mysql_query("SELECT * FROM pms WHERE to-id='".$_SESSION['id']."' LIMIT 1 per `thread` ORDER BY id ASC");
  </code></pre>
  
  <p>So that it will only show one link to a thread.</p>
  
  <p>What's happening now though is that it will show a new button, every time there is a reply to the thread. So, if there are 100 replies to message, and they're all in the same thread (since they're "replies") there will be 101 buttons, which is not ideal, for obvious reasons.</p>
  
  <p>Everything is currently working, except for that button limitation that I'm talking about.</p>