Last active
August 21, 2020 14:45
How is your internal query execution?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use blog; | |
-- Count posts id | |
SELECT COUNT(DISTINCT id) FROM posts; | |
-- => 7 | |
-- count posts id | |
SELECT COUNT(DISTINCT post_id) from comments; | |
-- => 3 | |
-- select all the posts that doesn't have comments | |
SELECT id FROM posts WHERE id NOT IN (SELECT DISTINCT post_id from comments); | |
-- => There are no results to be displayed. | |
-- hoooooow??? If I do this this works: | |
SELECT DISTINCT p.id | |
FROM posts p | |
LEFT JOIN comments c ON c.post_id = p.id | |
WHERE c.id IS NULL | |
-- => [1, 2, 3, 4] | |
-- ping me for the solution or add your comments here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your first one worked for me - http://sqlfiddle.com/#!9/1e130d/1