Php Mysql在条件相关查询中的应用

Php Mysql在条件相关查询中的应用,php,mysql,Php,Mysql,在上面的一个内部查询中,我给出了20个ac.id,但结果只得到了14条记录。如何获得总共20条记录。i、 如果条件中存在的id不满足,那么我应该在该id旁边创建一个值为0的记录 我该怎么做?一个简单的带条件的左连接应该可以: SELECT ac1.id, ac1.course_name, case when a.yettoapprove is not null then 'true' else 'false' end OrderedAll , a.* from (SELECT ac.id

在上面的一个内部查询中,我给出了20个
ac.id
,但结果只得到了14条记录。如何获得总共20条记录。i、 如果条件中存在的id不满足,那么我应该在该id旁边创建一个值为0的记录


我该怎么做?

一个简单的带条件的左连接应该可以:

SELECT ac1.id, ac1.course_name, case when a.yettoapprove is not null 
 then 'true'
 else 'false'
 end OrderedAll , a.* from (SELECT ac.id, sum(case when ad.status = '2' then 1 else 0 end) as yettoapprove , sum(case when ad.status = '1' then 1 else 0 end) as approved,case when ad.status = '2' is not null 
 then 'true'
 else 'false'
 end OrderedAll FROM aw_ou_student_data ad , jos_users ju , aw_ou_lookup_courses ac,aw_ou_lookup_colleges ac1 where ac1.id=ju.college_code and ac.id in (27,28,29,30,133,32,33,34,35,36,37,38,39,40,41,42,43,44,134,135) and ac.school_id=2 and ju.id=ad.user_id and ac.id=ju.course_code GROUP BY ac.id ORDER BY ac.id ) a left join  aw_ou_lookup_courses ac1 on ac1.id = a.id

我在上面的查询中也做了同样的事情,但它仍然没有出现。在上述问题中,我错在哪里。。
SELECT
    table1.id,
    table2.*
FROM
    table table1
    LEFT JOIN table2 ON table1.id = table2.id AND (your conditions here)