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 |
|
CNetSamR
Starting Member
1 Post |
Posted - 2007-10-19 : 16:11:25
|
| Is there a way I can write a SQL Select Statement where it picks a record based on a number field called ID (my primary key) and have it grab the highest numbered field?Thanks for any help in advance.-Sam |
|
|
graz
Chief SQLTeam Crack Dealer
4149 Posts |
Posted - 2007-10-19 : 16:16:07
|
| SELECT *FROM MyTableWHERE [ID] = (SELECT MAX([ID]) FROM MyTable)=================================================Creating tomorrow's legacy systems today. One crisis at a time. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-19 : 17:02:44
|
| moved from script library_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
Jenda
Starting Member
29 Posts |
Posted - 2007-10-21 : 11:40:00
|
quote: Originally posted by graz SELECT *FROM MyTableWHERE [ID] = (SELECT MAX([ID]) FROM MyTable)
Well, if the ID is the primary key, why not justSELECT TOP 1 * FROM MyTable ORDER BY ID Desc |
 |
|
|
graz
Chief SQLTeam Crack Dealer
4149 Posts |
Posted - 2007-10-21 : 12:10:36
|
| Ha! Yes, that would work also.=================================================Creating tomorrow's legacy systems today. One crisis at a time. |
 |
|
|
|
|
|