Teradata JoinsJoin is used to combine records from more than one table. Tables are joined based on the common columns and values from these tables. There are different types of Joins available in Teradata.
INNER JOINInner Join combines records from multiple tables and returns the values that exist in both the tables. Syntax Following is the syntax of the INNER JOIN statement. Example Consider the following two tables, such as the student table and attendance table. Student Table:
Attendance Table:
The following query joins the student table and attendance table on the common column Rollno. Each table is assigned an alias A & B, and the columns are referenced with the correct alias. When the above query is executed, it returns the following records. Rollno 1005 is not included in the result since it doesn't have matching records in the attendance table. OUTER JOINLEFT OUTER JOIN and RIGHT OUTER JOIN also combine the results from multiple tables.
Syntax Following is the syntax of the OUTER JOIN statement. We need to use one of the options from LEFT OUTER JOIN, RIGHT OUTER JOIN, or FULL OUTER JOIN. Example Consider the following example of the LEFT OUTER JOIN query. It returns all the records from the Student table and matching records from the attendance table. When the above query is executed, it produces the following output. For student 1005, % value is NULL, since it doesn't have matching records in the attendance table. CROSS JOINCross Join joins every row from the left table to every row from the right table. Cross Join is a Teradata specified join, which is equivalent to the product join. There will not be an "ON" keyword in the Cross Join. Syntax Following is the syntax of the CROSS JOIN statement. Example Consider the following example of the CROSS JOIN query. When the above query is executed, it produces the following output. RollNo 1001 from the Student table is joined with each and every record from Attendance Table. Rollno Rollno % 1001 1001 90% 1001 1002 72% 1001 1003 68% 1001 1004 95%
Next TopicTeradata SubQueries
|