Table is users, columns are user_id, firstname, lastname, area.
The other table is user_sessions, and columns are user_id, logon, logoff.
To see who is logged on I use
select u.FIRSTNAME, u.LASTNAME, u.PHONE_ID, us.LOGON
from USERS u
join USER_sessions us on u.USER_ID=us.user_id
where cast (us.LOGON as date) = date 'now'
and us.LOGOFF is null
order by u.FIRSTNAME
The result is correct, but sometimes I get duplicated entries.
For example, same firstname and lastname, but different logon. I'd like to only see the latest logon.
It looks like field
LOGONis kind of a timestamp type field; your question is not really precise, there.So, I think, you want the maximum value of
LOGON. For that, there is an aggregate functionMAX()which has to be used with aGROUP BY.You'll get the latest
LOGONfor every occurence ofu.FIRSTNAME, u.LASTNAME, u.PHONE_ID.Note, that you can use
current_datecontext variable instead ofdate 'now'cast.