基于多表的MySQL选择

时间:2016-06-20 00:29:00

标签: mysql

我有一个如下所示的查询:

SELECT Dashboard.idUser, Dashboard.idDashboard, 
Dashboard.text, Dashboard.date, Dashboard.visibility 
FROM Dashboard
JOIN Users_Settings ON Dashboard.idUser = Users_Settings.idUser
WHERE UNIX_TIMESTAMP(Dashboard.date) >= 0
AND Dashboard.deleted = 0
AND ( Dashboard.idUser IN 
 ( SELECT `idUser_b` FROM Friends WHERE `idUser_a` = 1 ) 
OR Dashboard.idUser IN 
( SELECT `idUser_a` FROM Friends WHERE `idUser_b` = 1) 
OR (Dashboard.idUser = 1) 
OR (Dashboard.visibility = 3 OR (Dashboard.idUser != 1 AND 
    (Dashboard.visibility != 2 AND Dashboard.visibility != 1)))
    )
OR Users_Settings.account_visibility != 1    
HAVING idUser IS NOT NULL
ORDER BY Dashboard.date ASC

这有效......有点儿。它将拉取结果,除了它不会排除朋友或其他用户的结果,其中Users_Settings.account_visibility!= 1

我在这个陈述中尝试了各种各样的事情但无济于事。

0 个答案:

没有答案