Ivan Ting
Ivan Ting

Reputation: 5

Select Distinct for only one column of value for Access

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.jpg

128101 |~/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

Answers (1)

goric
goric

Reputation: 11915

If you're just looking for a distinct list of ProductDesigns 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

Related Questions