Join or Merge
These are used to link data with another View based on a shared Column.
Mammoth provides another function, Lookup to achieve similar results. This task is an advanced version of the Lookup Task.
This is similar to a JOIN operation in an SQL database or a VLOOKUP
in Microsoft Excel
.
Quickstart
Let us start with the following two views.
Customers → View 1
:
ID | Name |
---|---|
1 | John |
2 | Katie |
3 | Priya |
4 | Raj |
Orders - View 1
ID | Customer ID | Subtotal | Tax | Total |
---|---|---|---|---|
1 | 2 | 151 | 15 | 167 |
2 | 1 | 89 | 9 | 98 |
3 | 4 | 89 | 9 | 98 |
The customer names are associated with the orders. Note that the customer ID column
has corresponding values in Customer → view 1
.
Orders - View 1
do the following:
- Go to the Combine menu.
- Select Join;
- Select
Customers → View 1
; - In select common keys section map
Customer ID
column toID
column; - Select the type of
Join
; - Select coulmns in the prefix selection box to add a prefix to the column names of
Customers
View; - Click APPLY.
This is the final result:
ID | Customer ID | Subtotal | Tax | Total | Customer.Name |
---|---|---|---|---|---|
1 | 2 | 151 | 15 | 167 | Katie |
2 | 1 | 89 | 9 | 98 | John |
3 | 4 | 89 | 9 | 98 | Raj |
It is possible to see which customers never placed an order too. Let us try to do that.
- Edit the last task.
- In the
Join Type
section, selectRight
. - Click APPLY.
The result would look like this:
ID | Customer ID | Subtotal | Tax | Total | Name |
---|---|---|---|---|---|
3 | Priya |
Supported Options
The following options are supported in this task:
View to Join with
: Allows selecting a view with which to join;Common keys
: Allows mapping between pairs of columns with common values;Join Type
: Allows one of four join types: Left, Right, Inner or Outer;- Mammoth does not allow certain type of joins. For more information, see restrictions .
You can also join text columns to numeric columns and vice versa in Mammoth, given the values in the columns match. For example, you can join a numeric column with say a value '25' and a text column with the same value '25', without converting the text column to numeric datatype first. Mammoth casts the values to the appropriate type for the join.
Join Types
Left Join
This option selects all the rows from the current View along with the matching rows from the current view.
Right Join
This option selects all the rows from the other View along with the matching rows from the current View based on the join key.
Inner Join
This option selects only matching rows from the current View and the other View where the Join condition is met (if at all).
Outer Join
This option selects all the rows from the current View and the other View, regardless of whether the join condition is met.
Restrictions
Mammoth does not allow Join rules of cyclic manner, i.e. If View-1 has a Join rule with View-2, then View-2 cannot have a Join rule with View-1. (See the following diagram). It creates a chain of data updates between the Views.
The cyclic behaviour can also occur when more than two Views are involved. (See the following diagram)