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 |
|
josh777
Starting Member
12 Posts |
Posted - 2007-03-01 : 20:42:31
|
| Hi people, I have a situation in which i need to retrieve the last row inserted of a particular group record. Ex: Item Group Prices A 27 A 15 A 19 B 22 B 7 C 11 D 44I want a query to retrieve the last inserted data of each groupie A 19 B 7 C 11 D 44Thanks a lot for ur helpJosh |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-03-01 : 23:29:28
|
"last row" implies an order. there is no order of rows in a table unless you specify one with an order by clause. do you mean that last one in time? if so do you have a datetime column that specifies when it the row was created? or if you have an identity column, you could use that to tell which row of a particular group was entered last. www.elsasoft.org |
 |
|
|
mahesh_bote
Constraint Violating Yak Guru
298 Posts |
Posted - 2007-03-02 : 06:36:47
|
quote: Originally posted by josh777 Hi people, I have a situation in which i need to retrieve the last row inserted of a particular group record. Ex: Item Group Prices A 27 A 15 A 19 B 22 B 7 C 11 D 44I want a query to retrieve the last inserted data of each groupie A 19 B 7 C 11 D 44Thanks a lot for ur helpJosh
If u have column for datetime in ur table, u can write it likeSelect Col1, Col2, Max(DateCol) From Table Group By Col1, Col2It is reqd to be Datetime col should be in table, unless u can't get the desired recordset. Or do u have pk in ur table. If Yes, it will be also helpfull. u can group ur query on that PK.Mahesh |
 |
|
|
josh777
Starting Member
12 Posts |
Posted - 2007-03-02 : 14:07:23
|
| Thanx but the problem is even when i have an identity is there a way i can get all the item groups with the last inserted record Item Group Prices SerialA 27 1A 15 2 A 19 3 B 22 4B 7 5C 11 6D 44 7I want a query to retrieve the last inserted data of each groupie A 19B 7C 11D 44Thanks again josh |
 |
|
|
|
|
|