Hi,
I'm trying the below query in my code (selecting a set of users who are proficient in a set of competencies):
$potentialusersquery="SELECT uc.id as id, uc.userid, u.id, u.alternatename as employee, u.email, u.department, count(*) as count FROM mdl_competency_usercomp uc
left join mdl_user u on uc.userid=u.id
and u.suspended=0
where uc.userid not in (select userid from mdl_competency_plan where templateid =? and status=1)
and uc.competencyid in (?)
and proficiency=1
group by uc.userid";
$potentialusers=$DB->get_records_sql($potentialusersquery,array($data->orgroles,$competencylist));
Problem is that count is always returned as 0. when I execute the query directly in DB, there are counts like 4,3,2, etc.
I read about the solution of having a unique id column as the first field for get_records_sql. I believe my query is meeting that requirement. still I'm not getting the required result.
Any clue on where am I going wrong?
Jack