Last active
August 21, 2020 14:45
-
-
Save gabidavila/25eec2e8117b89e7aadb10ae07128d88 to your computer and use it in GitHub Desktop.
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
You are correct @gingerCodeNinja