The Artima Developer Community
Sponsored Link

Java Buzz Forum
Difference between UNION vs UNION ALL in SQL

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
Difference between UNION vs UNION ALL in SQL Posted: Sep 3, 2014 7:02 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: Difference between UNION vs UNION ALL in SQL
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
Difference between UNION and UNION ALL is one of the tricky SQL question, especially for developers, who has not used this useful keyword ever. Since UNION clause is not as common as SELECT clause in SQL, it's usually asked in telephonic round of programming interviews to check whether candidate is comfortable with SQL or not. It's in the same league of questions like clustered vs non-clustered index or  primary vs unique keyUNION is very different than other SQL commands because it operates on data rather than columns. Anyway, answer of this question is simple, though both UNION and UNION ALL are used to combine result of two separate SQL queries on same or different table,  UNION does not keep duplicate record (a row is considered duplicate if value of all columns are same), while UNION ALL does. Since you mostly don't want duplicate rows,  UNION is preferred over UNION ALL in reporting and application development. By the way, you should keep in mind that UNION ALL performance better than UNION because it doesn't have to remove duplicate, so no extra work. This keyword is very well supported by all major database e.g. Oracle, Microsoft SQL Server, MySQL and PostgreSQL. Another thing to keep in mind is amount data returned by UNION ALL; if your database server is quite far away and you have limited bandwidth, UNION ALL may appear slower than UNION because of number of duplicates it returned. Cost of transferring duplicate row can exceed the query execution benefits in many cases. We will see couple of examples UNION and UNION ALL in SQL, but before that few things to keep in mind. In order to combine results of two queries, they must contain same number of columns. For example if one query contains 3 columns and other contains 4 columns then you can not use UNION or UNION ALL. This is because a row will only be considered duplicated when all column will have same value, irrespective of name of columns itself.
Read more »

Read: Difference between UNION vs UNION ALL in SQL

Topic: Managers Manage Ambiguity Previous Topic   Next Topic Topic: Metrics: Good VS Evil

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use