並非所有的child
行都有parent
。該child
行有一個parent
只應獲取如果parent.deleted='0'
如果不存在LEFT JOIN,則忽略
如果LEFT JOIN content as parent
不存在,我怎麼忽略parent.deleted='0'
該行?
SELECT child.* FROM `content` child LEFT JOIN
content parent on parent.id=child.parentid AND child.submittype='2' WHERE child.username=?
AND child.deleted='0' AND parent.deleted='0'
ORDER BY child.id DESC LIMIT 12
我該如何做?我把parent.deleted='0'
放在WHERE條款中,但這隻有在parent
行存在的情況下才有效。
那麼你螞蟻只選擇parentid爲null或parent.deleted <>'0'的那些行? – andy 2014-10-11 09:01:51
是的,這是正確的 – user892134 2014-10-11 09:03:04