请简化一个mysql查询

时间:2013-08-09 19:40:47

标签: mysql

我有一个MySQL查询:

SELECT p.* FROM posts p
WHERE 
(
    p.userid in 
    (
        select blogid from abos where userid=11
    )
    OR p.userid = 11
) 
AND NOT EXISTS
(
    SELECT null FROM posts_denied r 
    WHERE r.post_id = p.id AND r.userid = 11
)
order by p.id DESC limit 5

我想删除“where in”子句...如何才能找到最佳性能查询语法?

1 个答案:

答案 0 :(得分:0)

SELECT DISTINCT p.*
FROM posts p
JOIN abos a
ON p.userid = a.blogid OR p.userid = 11
LEFT JOIN posts_denied r
ON r.post_id = p.id AND r.userid = 11
WHERE (a.userid = 11 OR p.userid = 11)
  AND r.post_id IS NULL
ORDER BY p.id DESC
LIMIT 5