INTRODUCTION TO JOINS IN TABLEAU
Join Requirements 1. Join Type Determines which rows are selected Inner Left/Right Full 2. Join Clause Determines how rows from different tables are combined Variables from both tables that are the same
Join Types http://blog.codinghorror.com/a-visual-explanation-of-sql-joins/ Inner Left (Right) Full Data has to be in BOTH tables Data has to be in LEFT (1 st ) table. Data in EITHER table. Right joins are just the opposite of Left joins, but more confusing they are not recommended. In other contexts, you may see Full, Left, and Right joins referred to as Outer joins. Thus, a Left Outer join is exactly the same as a Left join (same for Full and Right).
Join Clause Correct joins usually revolve around the Unique Row Key What combination of fields determines a UNIQUE row The variables that are the same in both tables Usually, variables have the same names, but this is not required Usually the Inner Join of the Unique Row Keys ID s are preferred over names when possible Examples (the unique row key for ENROLLMENT): STUDENT_ID ACADEMIC_YEAR ACADEMIC_TERM_ID CLASS_ID SECTION_ID
Toy Example Table A STUDENT_ID CLASS A UK 101 A MA 109 B UK 101 B CHE 105 B CIS 110 C WRD 110 Table B STUDENT_ID MAJOR A Business B Kinesiology D Nursing Join on STUDENT_ID Left Inner Full STUDENT_ID CLASS MAJOR A UK 101 Business A MA 109 Business B UK 101 Kinesiology B CHE 105 Kinesiology B CIS 110 Kinesiology C WRD 110 - STUDENT_ID CLASS MAJOR A UK 101 Business A MA 109 Business B UK 101 Kinesiology B CHE 105 Kinesiology B CIS 110 Kinesiology STUDENT_ID CLASS MAJOR A UK 101 Business A MA 109 Business B UK 101 Kinesiology B CHE 105 Kinesiology B CIS 110 Kinesiology C WRD 110 - D - Nursing
Toy Example 2 Keys Table A STUDENT_ID TERM CLASS A Fall UK 101 A Spring MA 109 B Fall UK 101 B Fall CHE 105 B Spring CIS 110 C Spring WRD 110 Table B STUDENT_ID TERM MAJOR A Fall Business A Spring Business B Fall Kinesiology B Spring Biology D Fall Nursing Left Join on STUDENT_ID and TERM STUDENT_ID TERM CLASS MAJOR A Fall UK 101 Business A Spring MA 109 Business B Fall UK 101 Kinesiology B Fall CHE 105 Kinesiology B Spring CIS 110 Biology C Spring WRD 110 - Left Join on STUDENT_ID only STUDENT_ID A.TERM CLASS B.TERM MAJOR A Fall UK 101 Fall Business A Fall UK 101 Spring Business A Spring MA 109 Fall Business A Spring MA 109 Spring Business B Fall UK 101 Fall Kinesiology B Fall UK 101 Spring Biology B Fall CHE 105 Fall Kinesiology B Fall CHE 105 Spring Biology B Spring CIS 110 Fall Kinesiology B Spring CIS 110 Spring Biology C Spring WRD 110 - -
Basic Rules of Thumb Start with table that most closely matches the population you need ENROLLMENT has one row for every class in which student is enrolled RETENTION includes some students NOT found in ENROLLMENT or other tables DEMOGRAPHICS includes an even larger set of students students Left join other tables onto this driver table Many of our STUDENT tables are designed so that the difference between Full/Left/Inner join is minimal E.g., Every student in STATS_PER_TERM is also in ENROLLMENT and vice versa
Unique Row Keys DEMOGRAPHICS STUDENT_ID STATS_PER_TERM STUDENT_ID, ACADEMIC_YEAR, ACADEMIC_TERM_ID, DEGREE_PROGRAM_TYPE ENROLLMENT STUDENT_ID, ACADEMIC_YEAR, ACADEMIC_TERM_ID, CLASS_ID, SECTION_ID RETENTION STUDENT_ID, ACADEMIC_YEAR, ACADEMIC_TERM_ID, COHORT_TYPE, (COHORT_GROUP) COURSE_DETAILS COURSE_ID, SECTION_ID, ACADEMIC_YEAR, ACADEMIC_TERM_ID
ENROLLMENT_STATS_PER_TERM_ DEMOGRAPHICS
MY_LISTS with RETENTION STUDENT_ID RETENTION_DATA NAME A List1 A List2 A List3 A List4 MY_LISTS.RESULT is the same as RETENTION.STUDENT_ID Returns the RETENTION data for each NAME-RESULT combo If a STUDENT_ID (RESULT) is in 4 lists (NAME), the RETENTION info will be joined to each of the 4 lists Here, a Left or Inner join should give you the same result Stick with Left for consistency. Works similarly with other tables (besides RETENTION)
BAD Examples Do NOT just use the Tableau default! RETENTION Left join to ENROLLMENT on STUDENT_ID Will return a row for every class student has taken for every term in RETENTION table Row multiplication! Put ACADEMIC_YEAR and ACADEMIC_TERM_ID in join clause! ENROLLMENT Left join to COURSE_DETAILS on ACADEMIC_YEAR, ACADEMIC_TERM, CLASS_ID SECTION_ID is also required, since classes have multiple sections in a term.