MySQL Forums
Forum List  »  Newbie

SQL join problems
Posted by: Steve Penney
Date: February 10, 2018 08:43PM

Hi There,

I suspect what i am trying to achieve cant be done but I thought I'd ask those much smarter than me before I try another approach.

Basically I have a table with items for sale. I also have a table with item images with a FK linked to the for sale items PK.

I was hoping to write 1 query to select all items from for sale table and the primary image in the linked table.
EG "SELECT tblForSaleItems.id, tblForSaleItems.desc, tblForSaleImages.imagePath FROM tblForSaleItems JOIN tblForSaleImages on tblForSaleItems.id = tblForSaleImages.FK_ForSaleItems where tblForSaleImages.primaryImage = 1"

This works fine until I have a for sale item with no corresponding image in the images table, as I would expect.

Is there a way to rewrite the query so that if there is no corresponding image, it will still return the for sale item with a null value for imagePath that I can catch in my PHP code?

Options: ReplyQuote


Subject
Written By
Posted
SQL join problems
February 10, 2018 08:43PM
February 10, 2018 08:58PM
February 10, 2018 10:06PM
February 10, 2018 10:15PM
February 10, 2018 10:30PM


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.