User Profile

Collapse

Profile Sidebar

Collapse
amilcar
amilcar
Last Activity: Sep 16 '11, 02:05 AM
Joined: Aug 18 '11
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • amilcar
    replied to How can I do a "Grouped TOP 1"?
    Thanks! I resolve it this way:

    I Have 2 tables, users, and cases, what I do is to call the users table with a subquery (inner query) to return only the latest case of that user (order by date)

    Something like this (simplified):

    Code:
    SELECT dbo.users.id, [B][U](SELECT TOP (1) CaseId FROM dbo.cases WHERE (dbo.cases.user = dbo.users.id) ORDER BY timestamp DESC) AS case[/U][/B] FROM         dbo.users
    See more | Go to post

    Leave a comment:


  • amilcar
    started a topic How can I do a "Grouped TOP 1"?

    How can I do a "Grouped TOP 1"?

    I dont know how to do this, given this table:

    Code:
    -----------------------------------
    CaseId | User  | Timestamp
    -----------------------------------
       1   |   1   | 01/26/2011
       2   |   3   | 03/12/2011
       3   |   2   | 03/20/2011
       4   |   1   | 04/16/2011
       5   |   3   | 05/17/2011
       6   |   1   | 05/06/2011
       7   |   1   | 08/18/2011
    What I need to do...
    See more | Go to post
No activity results to display
Show More
Working...