Use UNION http://dev.mysql.com/doc/refman/5.0/en/union.html
The second query needs to have same exact columns, just use a where on that one that will only pull rows with no images or one image. -- Robert Garcia President - BigHead Technology VP Application Development - eventpix.com 15520 Coutelenc Rd Magalia, Ca 95954 ph: 530.645.4040 x222 fax: 530.645.4040 [email protected] - [email protected] http://bighead.net/ - http://eventpix.com/ On Sep 15, 2010, at 9:09 AM, Fogelson, Steve wrote: > I have an SQL question. I am using the following code: > > SELECT p1.P_ID, c2.Cat_ID, p1.P_Name, i3.ImageTNFileName AS TNName, > c2.CPR_Seq_Number > FROM categoryproducts c2, products p1 > LEFT JOIN (Image i3) ON (i3.ImageTypeID=p1.P_ID) > WHERE (c2.Cat_ID=180 AND p1.P_Disable IS NULL) AND ((c2.P_ID=p1.P_ID)) > GROUP BY i3.ImageTypeID > ORDER BY C2.CPR_Seq_Number ASC, i3.ImageSeqNumber ASC > > The Image table may contain multiple, one or no images for each product. The > SQL works fine for products with one or more images. But if the product has > no images, it is not returned in the SQL result. If I remove the “GROUP BY”, > it includes products with no or one image, but products with multiple images > result in a row for each image. > > Can I modify this SQL to include one row for each product with no images, one > image and multiple images. AND the image for products with multiple images > should be the one with the smallest ImageSeqNumber. > > Thanks in advance for your time. > > Steve Fogelson > > To unsubscribe from this list, please send an email to [email protected] > with "unsubscribe witango-talk" in the body. ---------------------------------------- To unsubscribe from this list, please send an email to [email protected] with "unsubscribe witango-talk" in the body.
