Solved

Find Max unique  ID SQL

Posted on 2010-11-29
2
449 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 142

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now