www.webdeveloper.com
Results 1 to 2 of 2

Thread: SQL Help

  1. #1
    Join Date
    May 2010
    Posts
    135

    SQL Help

    I can't get what is the proper sql for this.

    So I have users_tbl and users_access_log_tbl tables. Users_tbl table have user_id and user_name column. Users_access_log_tbl table have user_id and date_time_last_login columns.


    If a user login, the Users_access_log_tbl will be inserted with the user id and time stamp of his login. So if that user log in 3 times, that user will have 3 records in user_access_log_tbl(obviously with 3 different time stamp). Now the user name of that user is in users_tbl. How can I query the two tables where the output is user name(the user name of the user should be only displayed once) and the date_time_last_login ( should be the users latest login date). Thanks..

  2. #2
    Join Date
    Sep 2011
    Posts
    59
    This is it

    select [user_name], max(l.date_time_last_login)
    from users_tbl u
    inner join users_access_log_tbl l
    on u.[user_id]=l.[user_id]
    group by [user_name]

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles