左连接问题与哪里AND

0 sql sqlite

这是一些硬编码语法.IPAddr是一个int,这是sqlite,将被移植到mysql.

语法不起作用AND V.IPAddr <> 0.可能是因为V是左连接而可能不存在(null?).我怎样才能让它成功V == null || V.IPAddr <> Val

select Post.id, name, body,
      (select count() from Votes where id=Post.id AND (type & 4)<> 0) as DV
   from Post 
left join Votes as V on V.id=Post.id
   where flag='1'  AND V.IPAddr <> 0 AND DV<1
   limit 1
Run Code Online (Sandbox Code Playgroud)

gbn*_*gbn 5

将外部过滤器移动到JOIN条件.否则,过滤器将其更改为INNER JOIN

select Post.id, name, body,
(select count() from Votes where id=Post.id AND (type & 4)<> 0) as DV
from Post 
left join Votes as V on V.id=Post.id AND V.IPAddr <> 0 
where flag='1' AND DV<1
limit 1
Run Code Online (Sandbox Code Playgroud)