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 |
|
feejaz
Yak Posting Veteran
68 Posts |
Posted - 2008-06-19 : 02:36:31
|
| Hi,I have to create the query in which I have to select complete row records according to the column "time" where the time is most recent entered.there are columns "username", "bookname", "Time" a asp 6/4/2008 6:02:00 AM b sql 6/4/2008 6:04:00 AM a php 6/4/2008 6:05:00 AM Navi |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-19 : 02:41:55
|
| SELECT * FROM TABLE WHERE Time=(SELECT MAX(Time) FROm Table)ORSELECT * FROM Table tINNER JOIN (SELECT MAX(Time) AS MaxTime FROM Table)tmpON tmp.MaxTime=t.Time |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-06-19 : 02:43:11
|
quote: Originally posted by feejaz Hi,I have to create the query in which I have to select complete row records according to the column "time" where the time is most recent entered.there are columns "username", "bookname", "Time" a asp 6/4/2008 6:02:00 AM b sql 6/4/2008 6:04:00 AM a php 6/4/2008 6:05:00 AM Navi
The question is not clear please specify how you want your output to be. Any way if u want to get latest record from any tableuse thisselect top 1 * from table name order by time desc |
 |
|
|
feejaz
Yak Posting Veteran
68 Posts |
Posted - 2008-06-19 : 03:31:39
|
| thanks for reply,it is running for me, can you tell me If I want to get the record as per user also.Navi |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-19 : 03:58:13
|
quote: Originally posted by feejaz thanks for reply,it is running for me, can you tell me If I want to get the record as per user also.Navi
didnt get that. record as per user? |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-06-19 : 04:17:11
|
SELECT TOP 1 * FROM Table ORDER BY Time DESCSELECT UserName, BookName, TimeFROM (SELECT UserName, BookName, Time, ROW_NUMBER() OVER (PARTITION BY UserName ORDER BY Time DESC) AS RecIDFROM Table) AS dWHERE RecID = 1 E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|
|
|
|