I am trying to make an sql query that get all the results of people at a certain status ( A.attendance_status_id = 1
) for a particular event, but I also want to include an extra person who may have a different status.
So far I have tried including an OR for just that user_id ( A.user_id = 2
):
SELECT A.user_id AS attendeeId, S.name as status, U.first_name as firstName, U.last_name as lastName, A.date_of_interest AS dateOfInterest
FROM event_attendees as A
JOIN user as U ON A.user_id = U.id
JOIN attendance_status as S ON A.attendance_status_id = S.id
WHERE A.event_id = 3 AND A.attendance_status_id = 1 OR A.user_id = 2
ORDER BY A.date_of_interest
however that includes all of the other events that user is in, when I only want the user status for this particular event.
Is there any way to include that users status to a particular event as well as everyone else who has an attendence_status_id = 1
?
Thanks
Add your additional condition in query and try
SELECT A.user_id AS attendeeId, S.name as status, U.first_name as firstName, U.last_name as lastName, A.date_of_interest AS dateOfInterest
FROM event_attendees as A
JOIN user as U ON A.user_id = U.id
JOIN attendance_status as S ON A.attendance_status_id = S.id
WHERE (A.event_id = 3 AND A.attendance_status_id = 1) OR (A.user_id = 2 and ADDITIONAL_CONDITION)
ORDER BY A.date_of_interest
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.