Mysql: Perform of NOT EXISTS. Is it possible to improve permofance?
Posted
by petRUShka
on Stack Overflow
See other posts from Stack Overflow
or by petRUShka
Published on 2010-06-07T21:33:31Z
Indexed on
2010/06/07
21:42 UTC
Read the original article
Hit count: 320
I have two tables posts and comments. Table comments have post_id attribute. I need to get all posts with type "open", for which there are no comments with type "good" and created date MAY 1.
Is it optimal to use such SQL-query:
SELECT posts.* FROM posts
WHERE NOT EXISTS (
SELECT comments.id FROM comments WHERE comments.post_id = posts.id
AND comments.comment_type = 'good' AND
comments.created_at BETWEEN '2010-05-01 00:00:00' AND '2010-05-01 23:59:59')
I'm not sure that NOT EXISTS is perfect construction in this situation.
© Stack Overflow or respective owner