SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with query to get last occurence from log db

    I have a log db and I log when each user logs into the app in my log system. I want to pull up the last time each user logged in. So I want a list with a single tuple for each username and the LAST time they logged in. I am trying to use this right now:
    SELECT Time as t , Message as m FROM logMe WHERE Level ='monitor' AND Project ='login' GROUP BY m ORDER BY t DESC
    The trouble is that the order by happens after the grouping so I get a list ordered by Time DESC for the FIRST occurance that each person logged in.

    Any ideas how I can get this right?

    Thanks for the help.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,216
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by deuce868
    I want to pull up the last time each user logged in.
    Code:
    select user, max(logtime) as last_login
      from yourtable 
    group by user
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Max funtion worked perfectly. Thanks
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •