Practicle 10
Practicle 10
XI. Exercise
e)
INSERT INTO emp2 (empno, ename, deptno) VALUES (10, 'Adam', 50);
To display a output
SELECT * FROM emp2;
ename
John
Mike
Sara
Tom
Jane
Sara
Emily
John
Tom
Adam
ename
John
Mike
Sara
Tom
Jane
Emily
Adam
Output:
ename
Sara
John
Tom
Output:
ename
Jane
Tom
X. Practical related questions
1. Explain the need of set operators in SQL
Ans –
Set operators in SQL allow us to combine the results of two or more SELECT queries into a
single result set. These operators are crucial for performing operations that involve
comparisons and combinations of data across multiple tables or query results. The main set
operators in SQL are:
1. UNION
2. UNION ALL
3. INTERSECT
4. EXCEPT (or MINUS in some databases)
SQL provides set operators to combine the results of two or more queries. These set
operators treat the results as mathematical sets and allow us to combine, intersect, or subtract
them. The primary set operators in SQL are:
1. UNION
2. UNION ALL
3. INTERSECT
4. EXCEPT (also known as MINUS in some databases)
Each operator works on multiple result sets produced by SELECT statements and requires
the result sets to have the same number of columns and compatible data types.
1. UNION
The UNION operator is used to combine the results of two or more SELECT queries and
removes duplicate rows. This operator returns only distinct values from the combined result
sets.
Syntax:
SELECT column_list FROM table1 UNION SELECT column_list FROM table2;
2. UNION ALL
The UNION ALL operator is similar to UNION, but it does not remove duplicate rows. It
returns all rows from both result sets, including duplicates.
Syntax:
SELECT column_list FROM table1 UNION ALL SELECT column_list FROM table2;
3. INTERSECT
The INTERSECT operator returns only the rows that are common to both result sets. In other
words, it returns the intersection of the two sets.
Syntax:
SELECT column_list FROM table1 INTERSECT SELECT column_list FROM table2;
The EXCEPT operator (known as MINUS in some databases like Oracle) returns the rows
that are present in the first result set but not in the second. It is used to subtract one result
set from another.
Syntax:
SELECT column_list FROM table1 EXCEPT SELECT column_list FROM table2;
a)
SELECT ename FROM emp1 UNION ALL SELECT ename FROM emp2;
b)
c)
d)
SELECT ename FROM emp1 WHERE deptno IS NULL UNION SELECT ename FROM emp2 WHERE
deptno IS NULL;