views:

71

answers:

1

Hi guys,

I have a query I need some help with, have been checking out a fair few tutorials but nohting I found covers this issue.

I have three joined tables, Products,ProductImagesLookUp and Images.

A product can have any number of Images and the Order of the Images for a Product are stored in ProductImagesLookUp.

I need to return a list of products with their primary Image (the one with the lowest order value).

The list looks like this

Product
Images
LookUpId FileID Order    ProductTitle               Price   ProductId 
65       2    1 Amari Summer Party Dress 29.99    7
66       1    2 Amari Summer Party Dress 29.99    7
67       3    3 Amari Summer Party Dress 29.99    7
74       4    5 Beach Cover Up                 18.00   14
75       5    4 Beach Cover Up                 18.00   14
76       7    6 Beach Cover Up                 18.00   14
77       8    7 Beach Cover Up                 18.00   14
78       9    8 Beach Cover Up                 18.00   14
79       10    9 Amari Classic Party Dress 29.95   15
80       11    11 Amari Classic Party Dress 29.95   15
81       12    10 Amari Classic Party Dress 29.95   15

I want my query to pull back a list of distinct products which have the lowst Order value. I.e. it shoudl pull back the rows with the ProductImagesLookUpId of 65 (Product 7),74 ( Product 14) and 79 (Product 15).

Thanks in advance for your help. this one has really had me pulling my hair out!

+1  A: 
Tomalak
Thanks for the speedy and elegent answer Tomalak. Much appreciated!
CountZero