title: Select Query in sql with testing on each row
body: <p>i have the following query:</p>
  
  <pre><code>SELECT favorite_id,MO,name,b.image_id,image_path FROM buddies b,images i where reg_id=@regID and b.image_id=i.image_id
  </code></pre>
  
  <p>the field b.image_id in buddies should b tested before getting the image_path from the table images... if the image_id is 0 i have to the the image_id from a table registration and the get the image_path from the table image and if the image_id is different than 0 i directly get the image_id from the table images... so when selecting the favorite_id and the image_id from table buddies i need to loop on this table for every row and test the image_id </p>
  
  <p>can anyone help me?</p>