简体   繁体   English

加入用户和关注者表

[英]join user and follower table

I have user table and follow table in follow table I have user id - and - follower id 我有用户表,并且关注表中的关注表我有用户ID-和-关注者ID

I have to make list where I have to take email id of user and follower 我必须列出要接收用户和关注者的电子邮件ID的列表

how can I join both table 我怎样才能同时加入两个表

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

( now I want info of follower - how I can add ) – (现在我需要关注者的信息-如何添加)–

Join the bb_user table twice, aliasing as a (for user) and b (for follower). 加入bb_user表两次,别名分别为a (对于用户)和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

or with ANSI joins: 或使用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

Try this: 尝试这个:

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;

Heres an overall for you, the syntax iswrong, you need to JOIN ON 这是一个整体给您,语法错误,您需要加入

SELECT * FROM bb_follow f, JOIN bb_user a ON f.User_id = a.user_id WHERE f.Active_Status = '1' SELECT * FROM bb_follow f,JOIN bb_user a ON f.User_id = a.user_id WHERE f.Active_Status ='1'

Try that, then add your specific values 尝试一下,然后添加您的特定值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM