MySQL Forums
Forum List  »  Newbie

Re: SQL join problems
Posted by: Steve Penney
Date: February 10, 2018 10:06PM

Barry Galbraith Wrote:
-------------------------------------------------------
> Close, but not quite.
> Use a LEFT JOIN to get every row of the table on
> the LEFT side of the JOIN, and only the matching
> rows from the table on the right side of the JOIN.
>
> SELECT tblForSaleItems.id,
> tblForSaleItems.`desc`, -- desc is a reserved
> d word so must be enclosed in back ticks. Save
> yourself a LOT of grief and use a different name
> for the field.
> tblForSaleImages.imagePath
> FROM tblForSaleItems
> LEFT JOIN tblForSaleImages
> ON tblForSaleItems.id =
> tblForSaleImages.FK_ForSaleItems
> WHERE tblForSaleImages.primaryImage = 1;
>

Thanks Barry, Almost there.
I can get the join to work without the where clause, but the where clause necessitates a corresponding value in the tblForSaleImages table, so I'm not getting items without images.

I have tried adding an OR operator in the where statement like "WHERE tblForSaleImages.primaryImage = 1 or NULL but not successful.
Is this a case for a sub-query maybe?

Options: ReplyQuote


Subject
Written By
Posted
February 10, 2018 08:43PM
February 10, 2018 08:58PM
Re: SQL join problems
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.