What is the difference between join and union.

Answers were Sorted based on User's Feedback



What is the difference between join and union...

Answer / haritha

we can join two tables by 'join' if they have common
field.we can union two tables irrespective of common field.

Is This Answer Correct ?    316 Yes 148 No

What is the difference between join and union...

Answer / somashekhar m

Union : The union operator combines the results of two or
more queries into a single result set. But no.of columns
must match in both/all the queries (and also the order)
which are used for union.
Union -- returns with no duplicate rows
Union all -- retruns with duplicate rows (No. of rows
returned = No. of rows in Query1 + No. of rows in Query 2)
Union is a set operator.
You cannot use the union operator within a create view
statement.

You cannot use the union operator on text and image columns.

You cannot use the for browse clause in statements
involving the union operator.

Joins: Joins are used to extract information from more than
one table based on the related column/coloums (PK and RFK)
any no. of rows can be retrived based on matching matching
colums. Different types of joins are Inner join=equi join=
join, outer join(Right outer join/right join, Left outer
join/ left join), Cross join, and full outer join/outer join

Is This Answer Correct ?    139 Yes 20 No

What is the difference between join and union...

Answer / 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

What is the difference between join and union...

Answer / nand kumar

Join is used to established a conditional selection from 2
different tables, while union is used to select similar
data based on different conditions.

Is This Answer Correct ?    124 Yes 52 No

What is the difference between join and union...

Answer / thangamadasamy

A join selects columns from 2 or more tables. A union
selects rows

Is This Answer Correct ?    123 Yes 63 No

What is the difference between join and union...

Answer / vinay shukla

A join selects columns from 2 or more tables.
a union selects rows

Is This Answer Correct ?    60 Yes 20 No

What is the difference between join and union...

Answer / lalitha

join:

The SQL JOIN clause is used whenever we have to select data
from 2 or more tables.
To be able to use SQL JOIN clause to extract data from 2
(or more) tables, we need a relationship between certain
columns in these tables.

union:

The purpose of the SQL UNION command is to combine the
results of two queries together. In this respect, UNION is
somewhat similar to JOIN in that they are both used to
related information from multiple tables. One restriction
of UNION is that all corresponding columns need to be of
the same data type. Also, when using UNION, only distinct
values are selected (similar to SELECT DISTINCT).

Is This Answer Correct ?    35 Yes 11 No

What is the difference between join and union...

Answer / uchit shah

A Union and Join are similar in that they both are combining
two tables to form another table. However they do this
combining in different ways. The geometry is different.

Lets say for Table A and Table B
Union : -
|A|
-
|B|
-

Join : - -
| A | B |
- -

Union :
(1) In Union Two Rows of one table must fit onto the other
table. The Number of columns in the result table is the same
as the number in both tables. No new Columns are added.

(2) Maximum Number of rows = Sum of Number of rows in the
two tables.

Join :
(1) In Join the rows of one table may be different from the
rows of another table. The result table can contain columns
from both the first and second tables. It can contain all
the columns of first table and all the columns of second tables.

(2) Maximum Number of rows = Product of rows in two tables.

Is This Answer Correct ?    25 Yes 3 No

What is the difference between join and union...

Answer / tanu

UNION: Union Combines results of all select statements,
displaying duplicate rows only one time in the answerset.

Rules for usage:
1. All select clauses must have same number of expressions.
2. Corresponding expressions must have compatible domains.

First SELECT statement:
->Determines output format.
->Determines output title.

Last SELECT statement:
->Contains ORDER BY for the entire result, if required.

EXAMPLE:
SELECT first_name
,last_name
,'employee' (TITLE 'employee//type')
FROM employee
WHERE manager_employee_number = 1019
UNION
SELECT first_name
,last_name
,' manager '
FROM employee
WHERE employee_number = 1019
ORDER BY 2
;

RESULT:

first_name last_name employee_type
Carol Kanieski employee
Ron Kubic manager
John Stein employee

JOIN:
Join is a technique for accessing data from more than one
table in a single answerset. Each row in the answerset may
contain data from columns of more than one table. Tables
are joined on columns sharing common domain.

Is This Answer Correct ?    11 Yes 3 No

What is the difference between join and union...

Answer / kamruddin saha

Join can be implemented different numbers of column where as
Union is implemented same number of column in different tables
Ex:- Table1 Contains 5 column and Table2 contains 8 columns.
So we can get data of 3 columns from Table1 and 4 Columns
from Table2 using JOIN.

But using UNION we can get same number of column from both
table.Like 2 columns from Table1 and 2 columns from Table2.

Thank You

Is This Answer Correct ?    13 Yes 8 No

Post New Answer

More SQL PLSQL Interview Questions

What is pl/sql language case sensitive?

0 Answers  


What is the difference between local and global temporary table?

0 Answers  


what are the join types in tsql? : Transact sql

0 Answers  


Hi am new to PLSQL & facing problems in writing code like in SP, Functions, so any one having some SP coding with in depth explanation please share with me my Email ID suvarnaatsuvarna@rediffmail.com Or taking tanning on this please do contact me

0 Answers  


What is sql and db2?

0 Answers  






What are data types in pl sql?

0 Answers  


State some properties of relational databases?

0 Answers  


What is view? Can we update view

0 Answers  


what is the difernece between named and anonymous pl/sql blocks??

8 Answers   TCS, Wells Fargo,


What is the difference among union, minus and intersect?

0 Answers  


How can you save or place your msg in a table?

0 Answers  


What is Difference between StoredProcedure and function?

3 Answers  


Categories