MySQL Forums
Forum List  »  Newbie

Select subquery with joins
Posted by: José Puente
Date: May 26, 2015 01:47PM

Hello,
first of all, thank you in advance.

we have the following query to get data and i would like to know if there is another way to do it because for any new course we have to add a new subquery to get course status.

SELECT
user1.firstname AS Firstname,
user1.lastname AS Lastname,
user1.email AS Email,
if (exists( SELECT
ue.id
FROM mdl_user_enrolments AS ue
LEFT JOIN mdl_enrol AS en ON en.id = ue.enrolid
LEFT JOIN mdl_course AS course ON course.id = en.courseid
WHERE user1.id = ue.userid AND course.id = '1'), 'X', '') as "In course one"
FROM mdl_user AS user1
LEFT JOIN mdl_user_enrolments AS ue ON ue.userid = user1.id
LEFT JOIN mdl_enrol AS en ON en.id = ue.enrolid
LEFT JOIN mdl_course AS course ON course.id = en.courseid
WHERE user1.deleted='0'

Options: ReplyQuote


Subject
Written By
Posted
Select subquery with joins
May 26, 2015 01:47PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.