How to do inner join on two tables in Teradata

Scenario: How to I combine columns and rows in the following example in SQL without pulling extra rows with nulls on columns that not existing in the other table? 

\n\n

Table A

\n\n
EMP_ID        Dept_ID          VISIT_CA_DATE  \n001            01               5/2/2011                   \n002            02               null                     \n004            03               6/8/2011 \n
\n\n

Table B

\n\n
EMP_ID         Dept_ID        LAST_OUT        REASON  \n001             01             6/1/2011        sick  \n003             02             7/2/2011        vacation\n
\n\n

Expecting result:

\n\n
EMP_ID     Dept_ID   VISIT_CA_DATE     LAST_OUT       REASON      \n001         01         5/2/2011        6/1/2011        sick    \n002         02         null            null            null    \n003         02         null            7/2/2011        vacation    \n004         03         6/8/2011        null            null  \n
\n\n

Solution:

\n\n
SELECT A.EMP_ID,A.Dept_ID,A.VISIT_CA_DATE,B.LAST_OUT,B.REASON\nfrom TABLE_A A \nINNER JOIN TABLE_B B ON A.EMP_ID = B.EMP_ID AND A.DEPT_ID = B.DEPT_ID;


nVector

posted on

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds