MySQL Forums
Forum List  »  Newbie

SQL help please
Posted by: Steve Penney
Date: June 14, 2018 02:29AM

Hi There,

I am perplexed by a query that works on my dev machine but will not work on my web hosts machine.

I have a table of items for sale. I also have a table of product images with a 1-many relationship with the for sale items table.

I want to retrieve every for sale item and the product image with the lowest ID, and if there are no images, I want it to be a null value in the product image field.

the SQL is:
SELECT tblproducts.productID, tblproducts.productTitle, tblproducts.productDesc, tblproducts.productCost, T2.productImagePath
FROM tblproducts
(SELECT * FROM `tblProductImages` WHERE `tblProductImages`.`productImageID` IN ( SELECT MIN(`productImageID`) FROM `tblProductImages` GROUP BY `FK_Product`)) as T2
ON tblproducts.productID=T2.FK_Product

I don't care which product image is retrieved, I just want 1 image (or null) per product. As i said it works on my machine but not on the web hosts.

Any ideas?

Options: ReplyQuote

Written By
SQL help please
June 14, 2018 02:29AM
June 14, 2018 03:13AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.