Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is the difference between join and union.

Answer Posted / blue shark

JOIN:
-----

A Join is used for displaying columns with the same or
different names from different tables. The output displayed
will have all the columns shown individually. i.e. The
columns will be aligned next to each other.

UNION:
------

The UNION set operator is used for combining data from two
tables which have columns with the same datatype.
When a UNION is performed the data from both tables will be
collected in a single column having the same datatype.

For eg:

See the two tables shown below:

Table t1

Articleno article price manufacturer_id
1 hammer 3 $ 1
2 screwdriver 5 $ 2

Table t2
manufacturer_id manufacturer
1 ABC Gmbh
2 DEF Co KG

Now for performing a JOIN type the query shown below

SELECT articleno, article, manufacturer
FROM t1 JOIN t2 ON (t1.manufacturer_id =
t2.manufacturer_id);

articelno article manufacturer
1 hammer ABC GmbH
2 screwdriver DEF Co KG

That is a join.

UNION means that you have to tables or resultset with the
same amount and type of columns and you add this to
tables/resultsets together. Look at this example:

Table year2006

Articleno article price manufacturer_id
1 hammer 3 $ 1
2 screwdriver 5 $ 2

Table year2007

Articleno article price manufacturer_id
1 hammer 6 $ 3
2 screwdriver 7 $ 4

SELECT articleno, article, price, manufactruer_id
FROM year2006
UNION
SELECT articleno, article, price, manufacturer_id
FROM year2007

articleno article price manufacturer_id
1 hammer 3 $ 1
2 screwdriver 5 $ 2
1 hammer 6 $ 3
2 screwdriver 7 $ 4

Hope this helps!

Is This Answer Correct ?    107 Yes 11 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When to use inner join and left join?

903


What is scalar function?

998


What is difference between inner join and cross join?

909


What is offset in sql query?

1068


What are some predefined exceptions in pl/sql?

1063


What are the types pl/sql code blocks?

1066


What is mutating error in pl sql?

961


What is the purpose of primary key?

965


What are the different types of tables in sql?

928


What are the two types of cursors in pl sql?

1001


Show how functions and procedures are called in a pl/sql block.

1040


what is sub-query? : Transact sql

1038


what is cursor. write example of it. What are the attributes of cursor.

1308


What language is oracle sql developer?

937


Why primary key is required?

936