我想得到用户的共同朋友,即我关注的人和关注我的人:

# get users I'm following
following_ids = "SELECT followed_id FROM relationships WHERE follower_id = #{self.id}"

# get user that are following me
follower_ids = "SELECT follower_id FROM relationships WHERE followed_id = #{self.id}"

User.where("id IN (#{following_ids} INTERSECT #{follower_ids})")

但是,出现以下错误:

Mysql2 :: Error:您的SQL语法有错误; 检查对应于你的MySQL服务器版本使用附近的正确语法手册'INTERSECT SELECT follower_id FROM关系WHERE followed_id = 2))'在第1行:SELECT users 。* FROM users WHERE(ID IN(SELECT followed_id FROM关系WHERE follower_id = 2从关系中选择SELECTIONER_ID,WHERE followed_id = 2))

各个查询都能正常工作,因此我知道INTERSECT关键字存在问题。

===============>>#1 票数:0

MySQL没有INTERSECT 有关更多信息,请参见此处此处此处

  ask by Snowman translate from so

未解决问题?本站智能推荐:

关注微信公众号