如下是一评论表里有这么一条数据
id productid userid title grade commentcontents agreenaccount publicdate
1 5 1 test 5 this is test comments 0 2011-05-11当我使用select c.*,(case when(c.userid<>'0')then u.username else '游客' end) as 'username',
(case when(c.userid<>'0') then u.imgurl else 'images/hui_100_100.jpg' end)as 'imgurl'
from comments c join users u on c.userid=u.id or c.userid ='0' where 1=1 AND PRODUCTID='5'进行查询的时候,结果应该是应该是上面的一条数据可结果却出现了另外一条重复的记录说明下 userid=0是游客,在users表中是不存的的
id productid userid title grade commentcontents agreenaccount publicdate
1 5 1 test 5 this is test comments 0 2011-05-11当我使用select c.*,(case when(c.userid<>'0')then u.username else '游客' end) as 'username',
(case when(c.userid<>'0') then u.imgurl else 'images/hui_100_100.jpg' end)as 'imgurl'
from comments c join users u on c.userid=u.id or c.userid ='0' where 1=1 AND PRODUCTID='5'进行查询的时候,结果应该是应该是上面的一条数据可结果却出现了另外一条重复的记录说明下 userid=0是游客,在users表中是不存的的
(case when(u.id is not null) then u.imgurl else 'images/hui_100_100.jpg' end)as 'imgurl'
from comments c left join users u on c.userid=u.id where 1=1 AND PRODUCTID='5'