So I have 2 tables … Products and Images
Products
---------
id
value1
value2
value3
etc..
Images
---------
id
productId
imageName
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)
select p.*, i.imageName
from products p, images i
where p.id = i.productId and i.productId != 0
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) …
Currently the results look like this —
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...
I want it to look like this …
id: 1
imagename: name1.jpg
id: 2
imagename: name5.jpg
id: 3
imagename: name 3.jpg
Does this makes sense? Can anyone help me figure out my problem?
Something like this would work, although you will have to check it for typos.