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 |
|
de4ever@gmail.com
Starting Member
36 Posts |
Posted - 2009-04-15 : 01:24:31
|
| Hi all,Ihave a Table like thisver----docid-----------owner------name 1.00 HR-0001 1 New Bitmap Image.bmp 1.10 HR-0001 1 New Bitmap Image.bmp 1.20 HR-0001 1 New Bitmap_Image.bmp1.10 GEN-0001 1 abc.gif1.20 GEN-0001 1 abc.gif1.30 GEN-0001 1 abc.gif I need the records containing max version nover----docid-----------owner------name 1.20 HR-0001 1 New Bitmap_Image.bmp1.30 GEN-0001 1 abc.giffrom the tableplease help me out Thanks |
|
|
mithun.gite
Starting Member
3 Posts |
Posted - 2009-04-15 : 01:57:52
|
| SELECT * FROM My Table WHERE ver IN(SELECT MAX(ver) FROM My Table)Thanks & Regards, Mithun Gite |
 |
|
|
Kokkula
Starting Member
41 Posts |
Posted - 2009-04-15 : 02:13:36
|
| Hello,Try thisSELECT A.*FROM TableName AS AWHERE A.Ver = (SELECT MAX(B.Ver) Ver FROM TableName AS B WHERE A.DOCID = B.DOCID)ORSELECT A.*FROM(SELECT ROW_NUMBER() OVER(Order BY Ver Desc, Partition By DocID) AS ROW, A.*FROM TableName) AS AWHERE A.Row = 1Hope helpful...Thanks,Pavan |
 |
|
|
thiyagu_rind
Starting Member
46 Posts |
Posted - 2009-04-15 : 02:18:48
|
| Hey,You can useSelect Max(Ver),docid,owner,nameFrom TableNameGroup by docid,owner,nameRegardsThiyagarajan |
 |
|
|
de4ever@gmail.com
Starting Member
36 Posts |
Posted - 2009-04-15 : 03:34:30
|
| SELECT A.*FROM(SELECT ROW_NUMBER() OVER(Order BY Ver Desc, Partition By DocID) AS ROW, A.*FROM TableName) AS AWHERE A.Row = 1throwing syntax error near Partition By |
 |
|
|
Kokkula
Starting Member
41 Posts |
Posted - 2009-04-15 : 04:33:10
|
| Hello,Sorry it should be likeSELECT A.*FROM(SELECT ROW_NUMBER() OVER( Partition By DocID Order BY Ver Desc) AS ROW, A.*FROM TableName) AS AWHERE A.Row = 1Hope helpful...Thanks,Pavan |
 |
|
|
de4ever@gmail.com
Starting Member
36 Posts |
Posted - 2009-04-15 : 04:56:33
|
quote: Originally posted by Kokkula Hello,Sorry it should be likeSELECT A.*FROM(SELECT ROW_NUMBER() OVER( Partition By DocID Order BY Ver Desc) AS ROW, A.*FROM TableName) AS AWHERE A.Row = 1Hope helpful...Thanks,Pavan
Thanks Pavan ,it solved my problem with little change to the querySELECT A.*FROM(SELECT TableName.*,ROW_NUMBER() OVER( Partition By DocID Order BY Ver Desc) AS ROWFROM TableName) AS AWHERE A.Row = 1 |
 |
|
|
|
|
|
|
|