Reputation: 5
I want doing a datalistview of a product page.
Here is what I am using have now:
SELECT DISTINCT pProductDesign, pProductImage
FROM Product
WHERE (pProductDesign IS NOT NULL)
ORDER BY pProductImage
The results are:
pProductDesign|pProductImage
128101 |~/Images/128101-Cream.jpg
128101 |~/Images/128101-Gold.jpg128101 |~/Images/128101-Khaki.jpg
8680C |~/Images/8680C-Cream.jpg
8680C |~/Images/8680C-Gold.jpg
8680C |~/Images/8680C-Khaki.jpg
But what I want is just:
pProductDesign|pProductImage
128101 |~/Images/128101-Cream.jpg
8680C |~/Images/8680C-Khaki.jpg
Is there anyway to do it!?
Upvotes: 0
Views: 4380
Reputation: 11915
If you're just looking for a distinct list of ProductDesign
s and some arbitrary associated ProductImage
for each (as alluded to in the comments), you can use any aggregation function (min
, max
, average
) with a group by
:
select ProductDesign, max(ProductImage)
from Product
where ProductDesign is not null
group by ProductDesign
Upvotes: 3