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 |
|
PeterG
Posting Yak Master
156 Posts |
Posted - 2003-07-25 : 12:42:46
|
| How do I write the query that would display everything and filter out the record with the latest lngID for those with more than 1 account? For example, only 1 record (lngId=145513) should show for SCEDELI, DARREN.lngID txtName txtAccountNum txtCompanyNum txtUserId txtInternetCompNum 58852 SAELD, MARK 0000000000059857 213601657 salkeldm 124458844 SAASIN, EUGENE 0000000000059849 213601657 sarrasine 124458881 SCAB, JOCELYN 0000000000059886 1244 schaabj 1244111181 SCEDELI, DARREN 0000000000096656 213601657 SCHAEDELID 1244145513 SCEDELI, DARREN 0000000000126063 213601657 SCHAEDELIDA 1244119149 SCIDT, VAUGHN 0000000000103981 1244 ARMSTRONGR 1244127107 SCIDT, VAUGHN 0000000000111768 1244 PHIPPSLE 1244145510 SCIDT, VAUGHN 0000000000126584 1244 SCHMIDTVA 124460591 SHPE, NIALL 0000000000061440 213601657 sharpen 124460594 SHCHUK, TRENT 0000000000061443 213601657 shewchukt 124483360 SHCHUK, WILDEN 0000000000076342 213601657 SHEWCHUKW 124458865 SOMON, DAVE 0000000000059870 213601657 solomond 1244151307 SOERVILLE, MICHAEL 0000000000129226 213601657 NULL 1244119146 SPZ, NATACHA 0000000000103978 1244 WALDRONK 1244119888 SPZ, NATACHA 0000000000104720 1244 SPETZN 124458879 STWAY, BRIAN 0000000000059884 213601657 stanwayb 124458847 STPE, KEN 0000000000059852 213601657 stoupek 124458842 STM, LANCE 0000000000059847 213601657 stroml 124458839 SUEN, DARYL 0000000000059844 213601657 sugdend 124458886 SWAMER, GREG 0000000000059891 213601657 swinamerg 1244 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2003-07-25 : 13:07:40
|
| SELECT *FROM MyTableWHERE lngID IN (SELECT MAX(lngID ) as lngID -- Assuming MAX is latest?FROM MyTable GROUP BY txtName) |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-07-25 : 13:37:38
|
| That's pretty arbitrary. You've got to different accounts. Which one do you want to use?And to prevent this you need to add a unique constraint, so it doesn't happen again(Or we could get in to the whole FIRST() thing again)Brett8-) |
 |
|
|
|
|
|
|
|