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\nTable A
\n\nEMP_ID Dept_ID VISIT_CA_DATE \n001 01 5/2/2011 \n002 02 null \n004 03 6/8/2011 \n
\n\nTable B
\n\nEMP_ID Dept_ID LAST_OUT REASON \n001 01 6/1/2011 sick \n003 02 7/2/2011 vacation\n
\n\nExpecting result:
\n\nEMP_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\nSolution:
\n\nSELECT 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 onEnjoy 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
Post Comment