我涵盖了我最近的帖子 fetch results using join Mysql
我做了一些尝试。在我想要的水上
TABLE users
USERID NAMES EMAIL
1 KAT 1@1.com
2 JOHN 2@1.com
3 FIK 3@1.com
4 PET 4@1.com
5 COW 5@1.com
TABLE comunity
COMUNITY_ID USERID FANS
1 1 KAT #FROM TABLE USERS 3@1.com # FIK IS MY FAN
2 2 JOHN #FROM TABLE USERS 1@1.com # AM FAN OF JOHN
3 1 KAT #FROM TABLE USERS 5@1.com # COW IS MY FAN
4 4 PET #FROM TABLE USERS 1@1.com # AM FAN OF PET
5 1 KAT #FROM TABLE USERS 2@1.com # JOHN IS MY FAN
我想让所有在粉丝栏中有我的电子邮件的粉丝 我这样得到他们-可以工作
SELECT * FROM
users u
INNER JOIN comunity c ON u.USERID = c.USERID
WHERE c.FANS = 'MY USERID - 1'
现在问题出在这里
我还希望获得那些通过电子邮件发送给粉丝专栏的用户 我是这样做的 选择我的用户ID ='1'
的粉丝所以我需要在这里纠正
SELECT * FROM
users u
INNER JOIN comunity c ON u.USERID = c.USERID
WHERE c.FANS = 'MY USERID - 1'
AND * IN(SELECT c.FANS FROM comunity WHERE c.USERID = 'MY USERID - 1");
答案 0 :(得分:0)
您可以尝试以下查询:
SELECT * from
(
SELECT * from community where USERID=1 OR FANS='1@1.com'
) c
left join
users u
ON u.USERID = c.USERID;