We help IT Professionals succeed at work.
Get Started

SQL Query Help

97 Views
Last Modified: 2015-11-24
I have a list of Users in the system with User ID's, Application ID they accessed & sequence number for each step.  
Now I want to select a list of the latest applications accessed by user (With Sequence numbers).

Complete List
----------------------------------------------------------------------
|  User#  |    Application#       |     Sequence#    |
|      1       |              4                 |              1             |  
|      1       |              4                 |              2             |  
|      1       |              4                 |              3             |  
|      1       |              5                 |              1             |  
|      1       |              5                 |              2             |  
|      1       |              5                 |              3             |  

|      1       |              9                 |              1             |  
|      1       |              9                 |              2             |  
|      1       |              9                 |              3             |  
|      2       |              7                 |              1             |  
|      2       |              7                 |              2             |  
|      2       |              7                 |              3             |  
|      2       |              3                 |              1             |  
|      2       |              3                 |              2             |  
|      2       |              3                 |              3             |  

----------------------------------------------------------------------


Filtered List needed (Assume that each Application has a time-stamp used for access (We can compare time-stamps and let the latest application accessed for each user):
----------------------------------------------------------------------
|  User#  |    Application#       |     Sequence#    |
|      1       |              4                 |              1             |  
|      1       |              4                 |              2             |  
|      1       |              4                 |              3             |  
|      2       |              3                 |              1             |  
|      2       |              3                 |              2             |  
|      2       |              3                 |              3             |  
|               |                                  |                             |  
----------------------------------------------------------------------


Assume that the fields on the Table are "UserID", "ApplicationID", "SeqID".
The constraint is that I want the second list records in the same List order as the first. If user "1" comes before in the First list then that users records (All grouped records for the application selected) will come before in second list and so on.

Any ideas on how to format the Query?

Please let me know if I am not clear.
Comment
Watch Question
EE Topic Advisor
CERTIFIED EXPERT
Most Valuable Expert 2014
Awarded 2013
Commented:
This problem has been solved!
Unlock 3 Answers and 6 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE