SQL语句 关于当前用户是否关注某个作者

nice15616844791 2018-06-11 02:36:58
select topic.id,topic.content,
(case ifnull (attention.author_id,'否') when '否' then '否' else '是' end)
是否关注 from topic
left join attention on topic.user_id=attention.author_id


想查询根据当前用户查询关注的作者。怎么增加条件? 直接在SQL语句后面增加 attention.user_id = 1的话。就topic主表的数据不能全部显示出来了。


topic作品表表: attention关注表:
id id
title user_id 用户ID
content author_id 作者ID
user_id 作者ID
需求是:查询所有作者发布的作品。一个用户登录的时候看到自己关注的作者会显示这个作者是否自己关注过的。
...全文
903 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
stacksoverflow 2018-06-11
  • 打赏
  • 举报
回复
引用 5 楼 u014728451 的回复:
[quote=引用 4 楼 stacksoverflow 的回复:] [quote=引用 3 楼 u014728451 的回复:] [quote=引用 1 楼 stacksoverflow 的回复:] 问题描述好乱, and (attention.user_id is null or attention.user_id = 1)
你好。请问下 and 加哪里?[/quote] 加到where条件里,如果是第一个的话就是 where (attention.user_id is null or attention.user_id = 1)[/quote] 我试了。不是这样的效果。 能方便加一下Q。沟通一下吗? 841830537[/quote] 不好意思,我下班了。
nice15616844791 2018-06-11
  • 打赏
  • 举报
回复
引用 4 楼 stacksoverflow 的回复:
[quote=引用 3 楼 u014728451 的回复:] [quote=引用 1 楼 stacksoverflow 的回复:] 问题描述好乱, and (attention.user_id is null or attention.user_id = 1)
你好。请问下 and 加哪里?[/quote] 加到where条件里,如果是第一个的话就是 where (attention.user_id is null or attention.user_id = 1)[/quote] 我试了。不是这样的效果。 能方便加一下Q。沟通一下吗? 841830537
stacksoverflow 2018-06-11
  • 打赏
  • 举报
回复
引用 3 楼 u014728451 的回复:
[quote=引用 1 楼 stacksoverflow 的回复:] 问题描述好乱, and (attention.user_id is null or attention.user_id = 1)
你好。请问下 and 加哪里?[/quote] 加到where条件里,如果是第一个的话就是 where (attention.user_id is null or attention.user_id = 1)
nice15616844791 2018-06-11
  • 打赏
  • 举报
回复
引用 1 楼 stacksoverflow 的回复:
问题描述好乱, and (attention.user_id is null or attention.user_id = 1)
你好。请问下 and 加哪里?
nice15616844791 2018-06-11
  • 打赏
  • 举报
回复
你好。请问下 and 加哪里?
stacksoverflow 2018-06-11
  • 打赏
  • 举报
回复
问题描述好乱, and (attention.user_id is null or attention.user_id = 1)

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧