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 |
|
gulic
Starting Member
4 Posts |
Posted - 2009-03-28 : 07:08:06
|
| Could you help me with a select statement to obtain these results:unique serial with the max IDexample talble:ID Serial state23 123 ok25 134 no56 123 no46 134 okquery results: 56 123 no46 134 okthank you to much at all |
|
|
cshah1
Constraint Violating Yak Guru
347 Posts |
Posted - 2009-03-28 : 11:03:55
|
| SELECT t.ID,t.serial, t.state FROM Tinner join (SELECT MAX(ID) AS [ID]from Tgroup by serial) AS T1 on t.id = t1.id |
 |
|
|
gulic
Starting Member
4 Posts |
Posted - 2009-03-28 : 12:01:34
|
| doesn't work have you any other alternatives? |
 |
|
|
gulic
Starting Member
4 Posts |
Posted - 2009-03-28 : 12:21:25
|
| Is this the right way?SELECT dbo.TotOggiRSU.ID, dbo.TotOggiRSU.Serial, dbo.TotOggiRSU.DataOggi, dbo.TotOggiRSU.Ora, dbo.TotOggiRSU.TipoRifiuto, dbo.TotOggiRSU.Livello, dbo.TotOggiRSU.FlagError, dbo.TotOggiRSU.Batteria, dbo.TotOggiRSU.CoordX, dbo.TotOggiRSU.CoordYFROM dbo.TotOggiRSU INNER JOIN (SELECT MAX(ID) AS [ID]from dbo.TotOggiRSUgroup by dbo.TotOggiRSU.Serial) AS TotOggiRSU_1 ON dbo.TotOggiRSU.id = dbo.TotOggiRSU_1.id |
 |
|
|
gulic
Starting Member
4 Posts |
Posted - 2009-03-28 : 12:52:50
|
| Thank you so muchI found the solutions and now it work!!! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-29 : 03:25:22
|
if its sql 2005, this is sufficient,SELECT ID, Serial, stateFROM(SELECT ROW_NUMBER() OVER (PARTITION BY Serial ORDER BY ID DESC) AS Seq,ID, Serial, stateFROM Table)tWHERE Seq=1 |
 |
|
|
|
|
|
|
|