0

I have a simple database with tables u and l. Both these tables have user_id.

I have this query

Select u.user_ID, l.login_date as DATE
FROM 
u
INNER JOIN 
l
ON
u.user_id= l.user_id
WHERE
u.user_active = '1' order by DATE desc 

With this query, a list of user ids gets shown with the date. Is there a way to get only the latest date for which the user was active?

Shadow
  • 33,525
  • 10
  • 51
  • 64
Noname
  • 59
  • 1
  • 8

1 Answers1

0

Is there a way to get only the latest date for which the user was active?

This is just filtering and aggregation:

Select l.user_ID, l.login_date as DATE
from u join
     l
     on u.user_id = l.user_id
where u.user_active = 1  -- no quotes if this is a number
group by l.user_ID;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786