title: SQL select value from column when another column equals to given value
body: <p>I have a table called <code>payment</code>, which consists of the columns - <code>bill ID</code>, <code>group ID</code>, <code>u1</code>, <code>u1paid</code>, <code>u2</code>, <code>u2paid</code>, <code>u3</code>, <code>u3paid</code>, <code>u4</code>, <code>u4paid</code>, <code>u5</code>, <code>u5paid</code>. What I want to do is store the value of one of the paid columns <strong>if my currently set userID is equal to the ID stored in one of the columns u1, u2...,etc in the row I have selected</strong>. </p>
  
  <p>Example, if the current <strong>user ID</strong> is equal to the ID stored in <code>u3</code>, I'd like to store the value of <code>u3paid</code> in a PHP variable. What is the SQL command to achieve this?  </p>
  
  <p>An attempt at a solution: </p>
  
  <pre><code>SELECT u1paid if u1 = SessionID or u2paid if u2 = SessionID or 
  u3paid if u3 = SessionID or u4paid if u4 = SessionID or 
  u5paid if u5 = SessionID FROM payment WHERE billID = BILLID;
  </code></pre>
  
  <p>I know that this isn't proper syntax, but it's the closest I can get to something SQL-like. </p>
  
  <p>Second edit (on basis of twoleggedhorse's answer) :</p>
  
  <pre><code>$payment = "SELECT CASE WHEN u1 = '".$_SESSION['ID']."' THEN u1paid WHEN u2 = 
  '".$_SESSION['ID']."' THEN u2paid WHEN u3 = '".$_SESSION['ID']."' THEN u3paid 
   WHEN u4 = '".$_SESSION['ID']."' THEN u4paid 
   WHEN u5 = '".$_SESSION['ID']."' THEN u5paid END AS PAID 
   FROM payment WHERE trackbill = '".$row['BID']."';"
  </code></pre>
  
  <p>After that, I'm trying to access the value from this statement by $payment['PAID'], but it still isn't working. Am I still messing something up in this? </p>
  
  <p>Edit3 : The above command works, I just messed up one of the variable names :P </p>