我有一个查询

select c.CommentId
,c.CommentText
, c.CommenterId
, c.CommentDate
, u.first_name
, u.last_name
, i.ImageName
, i.Format
from comment c
join users u
  on  c.CommenterId = u.user_id
join user_profile_image i
  on u.user_id = i.UserId
where PostId = 76
 order
  by CommentDate desc
limit 10


当表中的i.ImageName字段为空时,此查询返回空结果。如果ImageName字段为emty,我想返回该行。我应该怎么做?

最佳答案

MySQL的JOIN默认为INNER JOIN-尝试更改

join user_profile_image i



LEFT join user_profile_image i

此处接受的答案具有良好的视觉解释:Difference in MySQL JOIN vs LEFT JOIN

关于mysql - sql查询表现奇怪,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33849256/

10-13 08:49
查看更多