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
~~Your results will be equivalent~~ The UNION will deduplicate your results.
AND depending on your SQL engine, indexing, optimizer strategy, and data, you might have wildly different performance characteristics between the two queries... If that matters to you
You can test this out yourself on the code below using SQLFiddle
Aye, looking at the replies, I'm becoming aware that I left out a couple key assumptions I've made. Assuming:
a)
id
is aPRIMARY KEY
(or otherwiseUNIQUE
)b) I mean
equivalent
insofar as "the rows returned will contain equivalent data same (though maybe ordered differently)"