SELECT DISTINCT itemid ,b.trackid,b.cmsitemid FROM
aa.iteminfo a
LEFT JOIN bb.trackinfo b ON (a.itemid=b.cmsitemid AND b.cmsitemid IS NOT NULL)
WHERE a.statusid=404 LIMIT 2
注意:以上sql,用的左连接,所以on后面的条件即便不满足,也会列出来
这时只能把b.cmsitemid is not null,放在where里才可以,
inner join是可以放在on后面的,在连接时就过滤