See All Rows from Different Postgres Tables with Union All

Brett Cassette
InstructorBrett Cassette
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

By default, union removes duplicate rows in the combined table. Union all, however, leaves all rows intact.

[00:07] We can select the name from backers and do a union and select the name from a set of acquired backers from some other acquired dataset we got. We can order by the name, and now it's not apparent here, but union actually does a distinct on the data.

[00:30] If there are duplicates between two different tables, they'll be removed here. We can throw in the ID column just to see what those duplicates are.

[00:42] We can see that Brad Pitt is in both tables, Duane Johnson is in both tables, Shamu is in both tables, Pam Beasley.

[00:50] We can actually still look up just the names and keep them distinct with union all. If we're interested in getting only these values, but we're interested in getting duplicates of the values for some reason, maybe to prove that they're in both tables, or do run a count over them, then we can do that with union all.

egghead
egghead
~ just now

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today