Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query help with SELECT DISTINCT

Status
Not open for further replies.

tnayfeh

Programmer
Apr 21, 2004
39
CA
I'm trying to get a list of users and their "last" or most recent login time which is stored in the field start_date_time from table ppes_request. Here's my query:

select distinct(user_name) from ppes_session, ppes_request
where ppes_request.session_id = ppes_session.session_id

This shows a list of all users, but I'm having difficulty adding the start_date_time to this statement.
What function will I need to use to just get their last login time and not a list of all their logins.

Thanks!
 
Code:
Select user_name, Max(start_date_time)
From ppes_session
     inner join ppes_request on ppes_request.session_id = ppes_session.session_id
Group By user_name


"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Try this query. It should return the max start_date_time for each user_name.

Code:
select user_name,
       Max(start_date_time) As LastLogin
from   ppes_session
       Inner Join ppes_request On ppes_request.session_id = ppes_session.session_id
Group By user_name

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top