0

我有一个如下用户表:

      id                      some attribute
1196670907478919031,fb39f78853bfe42279a8f56bc5671eb9,.....
4915018864030990478,44ecf841a778525b925023321761e458, ........
3161434036923224050,2fd54178a92a4b1a83643d9faa1fec9e,......

现在我有我的friendedges表如下

      a                          b               status
 '4915018864030990478', '3161434036923224050', 'accepted'
 '4915018864030990478', '1196670907478919031', 'accepted'

为了获得 id=4915018864030990478 的用户的所有朋友,我编写了以下查询,但我得到了以下结果查询

select id, firstName, lastName, gender, pictureSet  FROM  Member m JOIN  friendedges f ON f.a = m.id where a = "4915018864030990478";

结果

 '4915018864030990478', 'sdsds', 'dsd', 'M', '1'
 '4915018864030990478', 'sdsds', 'dsd', 'M', '1'

我必须在哪里获得朋友 ID。而且我不知道为什么它会产生重复的结果。

4

2 回答 2

1

用于DISTINCT删除重复项:

select DISTINCT f.b, firstName, lastName, gender, pictureSet  
FROM  Member m
JOIN  friendedges f ON f.a = m.id 
where f.a = "4915018864030990478";
于 2013-03-25T14:13:26.173 回答
0

你想要的是这个:

select f.id, f.firstName, f.lastName, f.gender, f.pictureSet
FROM Member m
JOIN friendedges e ON e.a = m.id
JOIN Member f ON e.b = f.id
where e.a = "4915018864030990478";

或更简单地说(如果您不需要会员的数据):

select id, firstName, lastName, gender, pictureSet
FROM  Member m JOIN  friendedges f ON f.b = m.id
where a = "4915018864030990478";

在第二个查询中,我只是更改f.af.b.

于 2013-03-25T14:13:16.143 回答