2012-07-23 118 views
1

我想從4個表中檢索數據:重複結果內部聯接查詢

  1. users_profile
  2. FRIEND_LIST
  3. bs_items
  4. bs.photos

我試圖找回由用戶的朋友上傳的產品,爲此我做了如下查詢

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次。誰能幫我這個?

回答

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 
+0

它正在重複結果。同樣的概率朋友 – 2012-07-23 09:59:19

+0

現在嘗試。我做了一些改變 – 2012-07-23 10:00:21

+0

沃拉,其工作非常感謝幫助:) – 2012-07-23 10:04:08