InterviewSolution
| 1. |
Explain the set operators in Teradata. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Answer» Operators such as SET combine the results from multiple SELECT statements. It may seem similar to Joins, but Joins combine columns from different tables, whereas SET operators combine rows from different tables. The following set operators are supported by Teradata SQL:
Example: Assume the student table below is TABLE1 and the attendance table is Table2.
1. UNION Following is a UNION query that combines the Roll_No values from both Table1 and Table2. SELECT Roll_No FROM Table1 UNION SELECT Roll_No FROM Table2;Output: Following is the output of the above query when executed. It does not includes duplicate values.
2. UNION ALL Here is an example of a UNION ALL statement. SELECT Roll_No FROM Table1 UNION ALL SELECT Roll_No FROM Table2;Output: Following is the output of the above query when executed. It includes duplicate values as well.
3. INTERSECT Here is an example of an INTERSECT statement. This command returns the Roll_No value that exists or present in both tables i.e., Table1 and Table2. SELECT Roll_No FROM Table1 INTERSECT SELECT Roll_No FROM Table2;Output: Following is the output of the above query when executed. The Roll_No105 is EXCLUDED because there is no such record in Table2.
4. MINUS/EXCEPT Here is an example of a MINUS/EXCEPT statement. SELECT Roll_No FROM Table1 MINUSSELECT Roll_No FROM Table2;Output: Following is the output of the above query when executed. Only Roll_No105 is INCLUDED because it is present in Table1 but there is no such record in Table2.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||