I'm looking for a little SQL help please

Associate
Joined
17 Nov 2003
Posts
1,913
Location
Gateshead
Hi,

I'm not much of a SQLer so looking for a little help.

Say I have the following table in SQL...

Question.jpg


I'm trying to build a sql string that returns the first instance of each [Username] based on the lowest [Index].

The resulting table would be...

Answer.jpg


Many thanks :)
 
Associate
OP
Joined
17 Nov 2003
Posts
1,913
Location
Gateshead
Afraid not...

Error...

"Column 'String' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."
 
Associate
OP
Joined
17 Nov 2003
Posts
1,913
Location
Gateshead
Can't use MIN(String) as I can't (don't want to) test against the value of a string.

Another way would be

SELECT * FROM Table A
WHERE A.index=(SELECT MIN(A1.index) FROM Table A1 WHERE A.Username=A1.Username))

This seems to do the trick :)

Cheers everyone for their help.
 
Back
Top Bottom