ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Databases >> SQL PLSQL
 
 


 

 
 Oracle interview questions  Oracle Interview Questions (2036)
 SQL Server interview questions  SQL Server Interview Questions (1076)
 MS Access interview questions  MS Access Interview Questions (24)
 MySQL interview questions  MySQL Interview Questions (194)
 Postgre interview questions  Postgre Interview Questions (6)
 Sybase interview questions  Sybase Interview Questions (22)
 DB Architecture interview questions  DB Architecture Interview Questions (5)
 DB Administration interview questions  DB Administration Interview Questions (213)
 DB Development interview questions  DB Development Interview Questions (53)
 SQL PLSQL interview questions  SQL PLSQL Interview Questions (773)
 Databases AllOther interview questions  Databases AllOther Interview Questions (106)
Question
What is the difference between join and union.
 Question Submitted By :: SQL-PLSQL
I also faced this Question!!     Answer Posted By  
 
Answer
# 1
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 ?    242 Yes 111 No
Haritha
 
Answer
# 2
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 ?    88 Yes 13 No
Somashekhar M
 
 
 
Answer
# 3
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 ?    114 Yes 47 No
Nand Kumar
 
Answer
# 4
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 ?    72 Yes 6 No
Blue Shark
 
Answer
# 5
A join selects columns from 2 or more tables. A union
selects rows
 
Is This Answer Correct ?    108 Yes 59 No
Thangamadasamy
 
Answer
# 6
A join selects columns from 2 or more tables.
a union selects rows
 
Is This Answer Correct ?    51 Yes 17 No
Vinay Shukla
 
Answer
# 7
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 ?    27 Yes 8 No
Lalitha
 
Answer
# 8
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 ?    19 Yes 2 No
Uchit Shah
 
Answer
# 9
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 ?    5 Yes 2 No
Tanu
 
Answer
# 10
join is used to combine two different tables where as in union

union also perform the same operation but the difference is
union will return distinct(unique) values.we can eliminate
the duplicate records while using union
 
Is This Answer Correct ?    3 Yes 1 No
Mohan
 

 
 
 
Other SQL PLSQL Interview Questions
 
  Question Asked @ Answers
 
Question: Below is the table city gender name delhi male a delhi female b mumbai male c mumbai female d delhi male e I want the o/p as follows: male female delhi 2 1 mumbai 1 1 Please help me in writing the query that can yield the o/p mentioned above?   2
Is it possible to use LONG columns in WHERE clause or ORDER BY?   1
what are the advantages of cursors than procedures?   2
Can i use Commit inside the Trigger? Suppose i use commit what will be happy (it's complied /executed/work)   6
What is mutating table? Saama-Tech 11
define primary key & secondary key?   2
What is nvl function? Cap-Gemini 3
Give which cursor is better for better performance means type of cursors?   2
What is normalization and types of normalization? Microsoft 22
i have a word ***********hello********world******. I require a o/p **********hello world**********, Need to delete the middle stars.   2
Write a query to find the employees from EMP table those who have joined in Monday. (there is a column as hiredate which is a date column i.e values are like 03-DEC-81)   3
What are different types of refreshment techniques of materialised view   2
 
For more SQL PLSQL Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com