this post was submitted on 10 Aug 2025
9 points (100.0% liked)
SQL
1051 readers
1 users here now
Related Fediverse communities:
- #sql on Mastodon
- #postgresql on Mastodon
- c/PostgreSQL on programming.dev
Icon base by Delapouite under CC BY 3.0 with modifications to add a gradient
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
It's equivalent because
UNION
removes duplicates; the behaviour you're describing happens withUNION ALL
. Since both queries are article.*, both halves will have the same columns and the dedupe will be successful.UNION
is less efficient because of this deduplication, but it's the default since that's what most people want. If that matters then you'd be correct that a JOIN version will be more efficient (possibly depending on indexes present and sql engine).