Solved

Find Max unique  ID SQL

Posted on 2010-11-29
2
452 Views
Last Modified: 2012-06-27
I have a table where In need to find the last transaction of a unique ID
Eg

SalesID     TransID      Name  
   85              197            xxxx
   85               199            xxxx
    85              285            xxxxxxxxxx
    85               167            xxxx
   106               298            xxxx
   106               402        xxxxxxxxxx
   106               588         xxxx


so the above I would want to return the max unique ID(TransID)  -  in the above case the highest TransID of each unique SalesID


Resuts Id wanted returned from the above.

SalesID     TransID      Name  
 85              285            xxxxxxxxxx
106               588         xxxx


   
0
Comment
Question by:edjones1
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 34230328
I have written this article:
http://www.experts-exchange.com/A_3203.html

one option would be:
select t.*
 from yourtable t
 where t.transid = ( select max(i.transid) from yourtable i wherei.SalesID = t.SalesID )

Open in new window

0
 

Author Closing Comment

by:edjones1
ID: 34230377
Perfect, Thanks
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question