有两张桌子 节点:
nid INT(10)
type (VARCHAR(32))
node_hit_count
nid INT(10)
totalcount (bigint(20))
我需要从nid
表中选择node
表中不在node_hit_count
表格中的所有WHERE
,node
feature
类型等于{{1} }或home
或competition
我尝试过,错了,我的思绪会被打击:/
select * from node left join node_hit_counter on node.nid=node_hit_counter.nid
where hit.nid is null and node.type IN ('feature', 'home', 'competition')
答案 0 :(得分:2)
hit.nid
子句中的WHERE
是什么。您必须使用WHERE node.nid IS NULL
,而不是这样:
select node.*
from node
left join node_hit_counter on node.nid = node_hit_counter.nid
where node.nid is null
and node.type IN ('feature', 'home', 'competition');
或强>
SELECT *
FROM node
WHERE nid NOT IN(SELECT nid FROM node_hit_counter WHERE nid IS NOT NULL)
AND type IN ('feature', 'home', 'competition');
答案 1 :(得分:1)
试试这个,你可以在where子句中使用你的hit.nid:o)
select n.*
from node n
left join node_hit_counter hit on n.nid=hit.nid
where hit.nid is null
and n.type IN ('feature', 'home', 'competition')