SQL: distinct on single field

Ivan Smahin ivan_smahin at valentina-db.com
Wed Mar 22 12:13:18 CST 2006


Hello Heinrich,

Wednesday, March 22, 2006, 12:02:31 PM, you wrote:

> Hi Igor,

> doesn't seem to work in my application.
> When I test the simple example in Valentina Studio
> I get the error:
> "In the SELECT clause you can use only fields listed in the GROUP BY and
> aggregative functions."

Sorry, It was too quick.

You could do following:

SELECT ProductCode, Min(Color), Min(id) FROM Products Group By ProductCode

Example:
ProductCode         Color       ...
-----------         ------
1                   2
1                   3
1                   4
...

Just  you  want  to  choose  single ProductCode value. Then you should
point  in some way which row should be chosen. So you have to use some
aggregative function - min, max, sum...



-- 
Best regards,
 Ivan                            mailto:ivan_smahin ÎÁ valentina-db.com



More information about the Valentina mailing list