Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Find Max unique  ID SQL

Posted on 2010-11-29
2
Medium Priority
?
458 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

722 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