2014-06-30 90 views
2

我有用戶表,並按照如下表表 我有用戶ID - 和 - 跟隨ID加入用戶和追隨者表

我必須做出列表,我必須考慮的用戶的電子郵件ID和隨

我怎麼能加入這兩個表

select f.USER_ID ,a.user_firstname, a.user_email ,f.Follow_Id 
from bb_follow f, bb_user a 
where a.user_id = f.User_Id and f.Active_Status=1 order by f.User_Id asc 

(現在我想跟隨的信息 - 我如何添加) -

+0

那你試試? –

+0

我現在嘗試從相同的用戶表我必須添加追隨者的名字和電子郵件ID –

+0

按照表(用戶名,followId,IsActive)用戶表(用戶名,名,emailid) - 謝謝 –

回答

-1

這裏有一個整體的你,語法iswro NG,你需要

SELECT *加入,從bb_follow樓 JOIN bb_user一個 ON f.User_id = a.user_id WHERE f.Active_Status = '1'

試一下,然後加入您的具體值

0

試試這個:

SELECT f.USER_ID, a.user_firstname userName, a.user_email userEmail, 
     f.Follow_Id, b.user_firstname followerName, b.user_email followerEmail 
FROM bb_follow f 
LEFT JOIN bb_user a ON a.user_id = f.User_Id 
LEFT JOIN bb_user b ON b.user_id = f.Follow_Id 
WHERE f.Active_Status=1 
ORDER BY f.User_Id ASC; 
1

加入bb_user表兩次,別名爲一個(用戶)和b(用於跟隨者)。

select f.USER_ID, a.user_firstname, a.user_email, 
     f.FOLLOW_ID, b.user_firstname as follower_firstname, b.user_email as follower_email 
from bb_follow f, bb_user a, bb_user b 
where a.user_id = f.User_Id 
and b.user_id = f.Follow_Id 
and f.Active_Status=1 

或ANSI連接:

select f.USER_ID, a.user_firstname, a.user_email, 
     f.FOLLOW_ID, b.user_firstname as follower_firstname, b.user_email as follower_email 
from bb_follow f 
     join bb_user a on a.user_id = f.User_Id 
     join bb_user b on b.user_id = f.Follow_Id 
where f.Active_Status=1 
+0

謝謝Mrjoltcola這是工作正常 –