MySQL查询以查找表中具有给定值的值,并查找其他类似值

MySQL查询以查找表中具有给定值的值,并查找其他类似值,mysql,sql,Mysql,Sql,我有一个名为followers的表,我希望能够找到当前用户的followers,显示该列表,然后将这些值与另一个用户ID进行比较,以查看他们是否在同一个表中跟踪它们 这是我当前用于获取特定用户的关注者列表的表: followers ------- followId - primary key, the unique id for the follow relationship userId - the user that is following someon

我有一个名为followers的表,我希望能够找到当前用户的followers,显示该列表,然后将这些值与另一个用户ID进行比较,以查看他们是否在同一个表中跟踪它们

这是我当前用于获取特定用户的关注者列表的表:

followers
-------
followId         - primary key, the unique id for the follow relationship
userId           - the user that is following someone
orgId            - that someone that the user is following
我尝试使用联合查询,但我不想这样做,因为性能原因表可能包含大量记录,而且我认为它不可伸缩


预期的输出应该是我正在检查的用户所遵循的orgId列表,以及显示我提供的用户my userId是否遵循orgId值的另一列,即下一列。

Hmmm,如果我理解正确,您有两个用户,您想知道哪个组织后面跟第一个,后面跟第二个:

select f.orgid,
       (exists (select 1
                from followers f2
                where f2.userId = $seconduserid and
                      f2.orgid = f.orgid
               )
       ) as seconduserflag
from followers f
where f.userId = $firstuserid

样本数据和预期结果,如表格文本,将有助于其他人帮助您。请向我们展示您现有的查询。你可能想看看。