Link to home
Start Free TrialLog in
Avatar of KAbbott
KAbbottFlag for United Kingdom of Great Britain and Northern Ireland

asked on

SQL Query help

Hi,

I have a data structure like this:

tblTest
nId,     txtSubTitle,     numSort
0         test1               0
1         test4               4
2         test2               2
3         test3               3
4         test4               2
5         test2               1
etc, etc...

I want to return each unique txtSubTitle with the lowest numSort value.
I thought this would work:

I tried "SELECT DISTINCT txtSubTitle, MIN(numSort) AS Expr1 FROM tblTest ORDER BY Expr1"

But I get an error message about GROUP BY clause, can anyone help?
ASKER CERTIFIED SOLUTION
Avatar of jefftwilley
jefftwilley
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
PS:
>But I get an error message about GROUP BY clause, can anyone help?
this is because of the DISTINCT, you cannot have DISTINCT and GROUP BY together.
reason: DISTINCT is actually a GROUP BY of all the output columns...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial