title: SQL Query Join Limit Results to One Item Per ID
body: <p>So I have 2 tables ... Products and Images</p>
  
  <pre><code>Products 
  ---------
  id
  value1
  value2
  value3
  etc..
  
  Images
  ---------
  id
  productId
  imageName
  </code></pre>
  
  <p>The image table will have more than one image per product,  so when I run this query:
  (the != 0 is because some images don't have a productId so I want to exclude them,  not sure if there is a better way to handle that, or if I even need to include that)</p>
  
  <pre><code>select p.*, i.imageName 
  from products p, images i 
  where p.id = i.productId and i.productId != 0 
  </code></pre>
  
  <p>I get the results, but it gives me multiple entries and I just want one result per product and i want it to pull up THE IMAGE THAT WAS ADDED FIRST  (so the oldest one) ... </p>
  
  <p>Currently the results look like this ---</p>
  
  <pre><code>id : 1
  imagename: name1.jpg
  
  id : 2
  imagename: name5.jpg
  
  id: 2
  imagename: name6.jpg
  
  id: 2
  imagename: name7.jpg
  
  id: 3
  imagename:  name3.jpg
  
  etc... etc... 
  </code></pre>
  
  <p>I want it to look like this ... </p>
  
  <pre><code>id: 1
  imagename: name1.jpg
  
  id: 2
  imagename: name5.jpg
  
  id: 3
  imagename: name 3.jpg
  </code></pre>
  
  <p>Does this makes sense?  Can anyone help me figure out my problem?</p>