您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

SQL选择行如果其他表中不存在任何行

SQL选择行如果其他表中不存在任何行

您可以not exists用来选择尚未与某个用户合作的所有用户

select * from
db_users dbu
where not exists (
    select 1 from db_likes dbl
    where dbl.relation in ('dislike','like','maybe') -- not sure if this is necessary
    and dbl.user = $oUser->id
    and dbl.partner = dbu.id
)

http://sqlfiddle.com/#!2/8c3bb9/6

SQLServer 2022/1/1 18:42:01 有434人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶