嗨,我具有以下数据库结构:

users包含:email, name

connections包含:followingemail, followedemail, isfollowedaccept

locations包含:location, email

在以下情况下,我想获取我朋友的namelocation:我的电子邮件的值为followingemail,我的朋友的电子邮件的值为followedemail

仅当我在connctions表中有一行包含我的电子邮件为followingemail和我朋友的电子邮件为followedemail并且isfollowedaccept为true时,它才应检索数据。

我的问题是如何编写该查询?

我不知道。谢谢。

最佳答案

尝试这个:

select u.name, l.location
from connections C
join users U on U.followedemail =  C.email
join location l on l.email =  C.email
where C.followingemail = (your email)
and   U.followedemail = (your friend's email)
and U.isfollowedaccept = true

08-18 09:03