Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Find Max unique  ID SQL

Posted on 2010-11-29
2
Medium Priority
?
460 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:Ed
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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:Ed
ID: 34230377
Perfect, Thanks
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

824 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