select c.*,MAX(cc.chapter_no) as chapter from comic c LEFT JOIN comic_chapter cc ON c.id=cc.comic_id AND cc.`status`=1 where c.author=20001926 and (c.`status`=1 or c.`status`=2)
这个sql是查不出数据的,comic表中就没有对应的数据,但是还是能查出一条每个字段都为null的数据,本人试了下把MAX函数去掉就不会出现这样的情况了,但是这个MAX是本人需要,问一下这个情况应该怎么查
解决方案
10
AND cc.`status`=1 放在where 后面呢
10
额,本人用的工具~假如使用命令行不会有这种情况!不好意思!
20
select c.*, (select MAX(cc.chapter_no) from comic c LEFT JOIN comic_chapter cc ON c.id=cc.comic_id AND cc.`status`=1 where c.author=20001926 and (c.`status`=1 or c.`status`=2) ) as chapter from comic c LEFT JOIN comic_chapter cc ON c.id=cc.comic_id AND cc.`status`=1 where c.author=20001926 and (c.`status`=1 or c.`status`=2)
速度很慢 建议还是在java中处理吧