I have the following MySQL query. The user_extra table can return multiple values for a given user_id. I would like only the latest a.session_date value from user_extra.
SELECT DISTINCT (user_id) user_id, a.value
FROM user_reg ap
JOIN user_extra a USING (user_id)
WHERE ap.session_date BETWEEN '2017-01-01' AND '2017-06-10' AND a.session_date<='2017-01-01'
Any ideas how I can do this?
select ap.user_id, ap1.value
from user_reg ap
inner join (
select user_id, max(session_date) as MaxDate, value
from user_extra
group by user_id
) ap1 on ap.user_id = ap1.user_id and ap.date = ap1.MaxDate
It will give maximum session date for single user id.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments