MySQL Forums
Forum List  »  Newbie

Re: Select subquery with joins
Posted by: Phillip Ward
Date: May 27, 2015 05:16AM

This kind of "Is is this? Is it that? Is it something else?" thinking is horrendously inefficient and, as you've discovered, a maintenance nightmare.
Ask the database to give you the data that's there and then deal with whatever you get back in your application layer - that's what it's for.

SELECT    u.firstname 
,         u.lastname 
,         u.email 
,         ue.courseid 
from      mdl_users u 
left join mdl_user_enrolements ue 
     on   u.id = ue.userid 
WHERE     u.deleted='0' 
order by  u.id ;

Yes, you get some duplication of data when a student is on more than one course, but if you really don't want that, then you need two selects - one to get the user data, another to get the courses and mash the two together in the application.

Regards, Phill W.

Options: ReplyQuote


Subject
Written By
Posted
Re: Select subquery with joins
May 27, 2015 05:16AM


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.