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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-03-15 : 07:54:31
|
| saif writes "This is the scenario:I have to pick latest Record for following 3 combinations set of data:first combination:PC_id P_id P_contact P_name audit_timestamp 1 1 a usa 2005-07-07 07:12:132 1 a uk 2005-07-07 07:12:133 1 a usa 2005-07-07 07:12:13---i have to pick PC_id = 3 since audit_timestamp is same i have to go for max (PC_id) so record # 3 will be selected.but in the same table I have other scenario:PC_id P_id P_contact P_name audit_timestamp 1 1 a usa 2005-07-07 07:12:133 1 a uk 2005-07-07 09:12:132 1 a usa 2005-07-07 11:12:13I have to select PC_ID = 2, since audit timestamp on it is latest. I have to come up with such a logic so that I pick latest P_name. i know it can be done through Store procedure but it would be great help if some one can help me with select qry for this scenario. Thanks" |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-03-15 : 07:57:25
|
| [code]select top 1 *from yourtableorder by audit_timestamp desc, PC_id desc[/code]----------------------------------'KH' |
 |
|
|
|
|
|