hi, i need to select data from 2 different tables. im using union.
the fields are activity_id, user_id, start_date and end_date. there are many activities and each user can attend these activities multiple times. for each user, i need to find the min start date and max end date for all the activities they attended.
so the final result will show each user, and the min start date and max end date
This is my sql:
SELECT qa.userid AS userid,q.id as act_id, MIN(from_unixtime(qa.start_date)) AS start_time,MAX(from_unixtime(qa.end_date)) AS end_time, 'swim' FROM swmimming q, swmimming_attemp qa, user u
WHERE q.id=qa.id AND qa.userid=u.id AND qa.id IN(1,2,3)
UNION
SELECT la.userid AS userid,la.lessonid as act_id,MIN(from_unixtime(la.start_date)) AS start_time, MAX('end_date') AS end_time, 'run' FROM running l, running_attemp la, user u
WHERE l.id=la.id AND la.userid=u.id AND la.id IN(1,2) GROUP by userid