Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
petek
Posting Yak Master
192 Posts |
Posted - 2008-08-14 : 10:32:54
|
Hi All,I am having problems with the following statementselect DISTINCT ([surname]), Match, [ni number]from HoldingtableFUZZYMatch where match >20 order by 1 asc , 2 descIt returns three columnsSurname, Match, Ni Numberit returns:Beames 60 123456789Beames 50 123456789Beames 44 123456789Beames 40 123456789Beames 36 123456789Beames 22 123456789Aitken 50 YK121182CAitken 40 YK121182CAitken 36 YK121182CAitken 33 YK121182CAlexander 62 987654321Alexander 57 987654321Alexander 53 987654321Alexander 47 987654321Alexander 46 987654321Alexander 42 987654321Alexander 40 987654321Alexander 37 987654321Allan 80 abcd123465Allan 60 abcd123465Allan 57 abcd123465Allan 55 abcd123465i need a select statement that returns the highest match and distinct name for exampleAllan has 4 rows and the highest match value of 80 so i need to return only that row, likewise with alexander the match value is 62 so need to return that row and so on for the other values...any ideas??Kind RegardsPete. |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-14 : 10:38:43
|
select * from HoldingtableFUZZYMatch as twhere match=(select max(match) from HoldingtableFUZZYMatch where match >20 and surname=t.surname)MadhivananFailing to plan is Planning to fail |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-08-14 : 11:27:58
|
Maybe this?SELECT Surname, MAX(Match) AS Match, [Ni Number]FROM HoldingtableFUZZYMatchWHERE Match > 20GROUP BY Surname, [Ni Number]ORDER BY Surname E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|