1

我正在尝试从 4 个表中检索数据:

  1. users_profile
  2. 好友列表
  3. bs_items
  4. bs.照片

我正在尝试检索用户朋友上传的产品,为此我进行了以下查询

select F.friend_id,F.status,F.uid, b.owner_id,b.price, b.currency, 
  b.item_name,b.item_id,bs.productId,bs.userId,bs.photo_thumb,u.uid,u.fname,
  u.lname, u.profile_pic 
from bs_items b,bs_photos bs,friend_list F,users_profile u 
where    F.status=1 and  F.uid='5' and U.uid=F.friend_id 
  and b.owner_id=F.friend_id 
  and b.item_id=bs.productId  and b.owner_id=bs.userId 
order by b.timestamp desc 

但上面的查询给了我想要的结果,但它重复了它们。例如,我有一个朋友上传了产品,然后记录被提取并重复了 5 次。谁能帮我这个?

4

1 回答 1

1

试试这个它可能对你有用。

select F.friend_id,F.status,F.uid, b.owner_id,b.price, b.currency,b.item_name,b.item_id,bs.productId,bs.userId,bs.photo_thumb,u.uid,u.fname,u.lname,u.profile_pic 
from users_profile u inner join friend_list F on u.uid=f.friend_id
Inner join bs_items b on b.owner_id=F.friend_id
inner join bs_photos bs on b.item_id=bs.productId 
where F.status=1 and F.uid='5' 
Group by F.uid
order by b.timestamp desc 
于 2012-07-23T09:58:26.793 回答