2017-11-28 9 views
0

나는 미니 소셜 미디어를 만들려고하는데, 나는 3 테이블을 가지고있다 :
Followdata | 상태 1 = 후, 0을 따르지 않을 경우 : - :MYSQL 3 테이블에서 선택하지만 결과는 Redudance입니다. 누구나 할 수있다.

idstatus email des_status 
    1  [email protected]  tes1 
    2  [email protected]  tes2 
    3  [email protected]  tes3 
    4  [email protected]  tes4 


사용자 :

email  username 
[email protected]  ima 
[email protected]  imb 
[email protected]  imc 


Emaildari> EmailKe이

emaildari emailke status 
[email protected]  [email protected]  1 
[email protected]  [email protected]  0 
[email protected]  [email protected]  1 
[email protected]  [email protected]  1 
[email protected]  [email protected]  1 
[email protected]  [email protected]  0 


상태 후속 B를 의미


Myquestion입니다 : 내가 사용자 이메일로 상태 (포스트)를 표시 할 수있는 방법 [email protected] 및 사용자 [email protected]에 의해 다음 그래서 같은 결과를 얻을 : C에서 상태 게시물을 @ c.com 따라 [email protected]


결과 나던 [email protected] 때문에 표시되지 않습니다 : 사전에

idstatus username des_status 
    1   ima   tes1 
    2   imb   tes2 
    3   imb   tes3 

이 제발 도와주세요 Thaks을.

내가 할 짓을
UPDATE :하지만 사용자 이름 결과가 동일합니다 상태 FROM

SELECT status.email, status.des_status, status.dibuat, users.username , 사용자, followdata where status.email = "[email protected]"또는 status.email = (followdata.emailke는 followdata.emaildari = "[email protected]"이고 status = "1"이면 선택) status.email = users.email GROUP (작성자 : id_status) ORDER BY dibuat DESC

결과 : Link Image

답변

0

시도 WHERE 절에 ()를 추가 :

SELECT 
    status.email, 
    status.des_status, 
    status.dibuat, 
    users.username 
FROM 
    status, 
    users, 
    followdata 
WHERE 
(
    status.email = "[email protected]" 
    or 
    status.email = 
    (
     SELECT followdata.emailke WHERE followdata.emaildari = "[email protected]" and status = '1' 
    ) 
) 
and status.email = users.email GROUP by id_status ORDER BY dibuat DESC