Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Condition using left join

Status
Not open for further replies.

hessodreamy

Programmer
Feb 28, 2005
59
GB
I'm having trouble constructing this left join query.
I want to retrieve all rows from tProducts, and relevant matches from pictures, however what I have got just jams up the server and I have to restart. Am I doing it wrong?

SELECT prodCode, prodName
FROM tProducts LEFT JOIN pictures
ON productID = relProdId
AND prodCode = 'SF2'
 
Can't see anything wrong there.

Presumably the productID and relProdId fields are in different tables? If they're both in the same table, that could cause massive problems.
 
Yes they are in different tables. On someones recommendation I have put indexes in now and the query runs, however what I find is that it returns ALL rows from tProducts, and disregards both conditions.

To clarify, I want all rows in tProducts where prodcode starts = SF, and any matching entry in pictures, but also showing null where there is no entry in pictures.
 
I've got it working now. I actually wanted prodcode like 'SF%'. This returns the correct rows, though I'm not sure why!

Thanks for help anyways.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top