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
  • 32,277
  • 10
  • 49
  • 61
Noname
  • 49
  • 1
  • 7

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,198,228
  • 53
  • 572
  • 709