Joining tables

Most databases have multiple tables of data that are related in some way. Additionally, with Tableau 10 and later, you are able to join together tables of data across various data connections for many different data sources. As we'll see, Tableau makes it very easy to join together tables of data relatively easy.

Consider, for example, tables such as these:

The primary table is the Hospital Visit table, which has a record for every visit of a patient to the hospital and includes details such as admission type (examples include inpatient, outpatient, and ER). It also contains key fields that link a visit to a Primary Physician, Patient, and Discharge Details.

When you connect to the database in Tableau, you'll see the tables listed on the left and will have the option to drag and drop them into the data source designer.

Typically, you'll want to start by dragging the primary table into the designer. In this case, Hospital Visit contains keys for joining additional tables. Those tables should be dragged and dropped after the primary table.

If key fields and relationships have been defined in the database, Tableau will automatically create the joins as you add additional tables. Otherwise, it will attempt to match field names. In any case, you may adjust the joins as needed. The preceding tables will look similar to the following diagram when dropped into the designer:

You may adjust the join by clicking the small diagram between the tables. The diagram indicates what kind of join is used. For example, the join between Hospital Visit and Patient is an Inner Join because it is assumed that every visit will have a patient and every patient will have a visit. However, the join between Hospital Visit and Discharge Details is a left join because some records in Hospital Visit may be for patients still in the hospital (so they haven't been discharged).

Clicking on the diagram will allow you to select a different type of join and define which fields are part of the join.

You may specify the following types of joins: