Mysql Rails SQL INTERSECT不工作
我希望获得用户的共同朋友,即我跟随的人和跟随我的人:Mysql Rails SQL INTERSECT不工作,mysql,sql,ruby-on-rails,Mysql,Sql,Ruby On Rails,我希望获得用户的共同朋友,即我跟随的人和跟随我的人: # 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 = #{
# 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服务器版本的正确语法
使用近“相交”从关系中选择跟随者id,其中
在第1行跟随_id=2':从id为
在中,从follower_id=2的关系中选择followerd_id
相交从跟随者id的关系中选择跟随者id=
二,
单个查询确实有效,因此我知道INTERSECT关键字有问题。MySQL没有INTERSECT。有关详细信息,请参见或