When building a data flow, joining tables is one of the most common steps you will take. This blog will break down exactly what a "non-equal" (or non-equi) join is, why you should join in Prep over Desktop as well as showcasing an example use case from a Preppin' Data Challenge - Link
What is a non-equal join?
When joining tables together, you often join columns that have matching values. Therefore when you join the tables together in Prep, you would use the equal operator (=).
However, your data won't always match perfectly. There are many scenarios where you need to connect tables based on a condition or threshold rather than an exact match. This is where non-equal joins (or non-equi joins) are more appropriate. These types of joins use relational operators to evaluate how the rows relate to one another.
The non-equal operators are:
- < less than
- > greater than
- >= greater than or equal to
- <= less than or equal to
- != not equal to
An example of where a non-equal join would be used is when checking if a specific event occurred within a defined timeframe. E.g. whether or not a customer's order occurred within a promotional period.
Advantages and Disadvantages of joining in Prep over Desktop
- Doing the joins in Prep means that you do not have to take up memory by doing them live in Desktop.
- However, the main disadvantage of doing it in Prep is that the join is static. If you wanted to change a data threshold based on a parameter, that would not be possible in Prep.
Example of using Non Equal Join
The example that I will use to illustrate this will be from the Preppin' Data Challenge: Week 16 (2023). In the task, we were asked to compare historical Easter dates and Full Moon dates to see whether or not this definition of Easter Sunday was correct:
"The simple standard definition of Easter is that it is the first Sunday after the full Moon that occurs on or after the spring equinox. If the full Moon falls on a Sunday then Easter is the next Sunday."
We were given the following tables:

To calculate whether or not Easter Sunday followed the rule, we had to join together our Easter Sunday column and Date column from the two tables. An equal join would not work here as Easter Sunday and the Full Moon rarely fall on the same day. Instead, we used a non-equal operator to be able to view the Full Moons that happened before each Easter. Because our definition states Easter as falling after a Full Moon, we joined our tables where Easter Sunday was greater than or equal to (>=) the Full Moon date.

Data Inflation Problem
Whilst this non equal join successfully leaves us with Full Moon Dates each year that are less than the Easter Sunday dates, it also introduces a significant data inflation problem. The join clause only checks for when an Easter date is greater than a Full moon date therefore, whilst an Easter Sunday in 2023 is chronologically greater than a 2023 Full Moon, it is also greater than every single Full Moon back to 1900. This causes our data to explode to almost 95,000 rows.
To solve this issue, we can add another join clause to restrict the timeframe. By extracting the year from both dates using a calculated field, we can create a join clause where Year(Easter Sunday) = Year(Full Moon). This cuts down the total rows to just 459.

As seen above in the red box, the results of this join only leave us with every Full Moon date in a given year that falls before that year's Easter Sunday. You can see this in the Full Moon Date column: for 1900, the dates from 15/01/1900 through 15/04/1900 are all included (shown in black), while everything from 14/05/1900 till the end of the year is excluded (shown in red) since it falls after that year's Easter Sunday. Since each year returns multiple matching Full Moon dates rather than a single one, we'll need to filter the results afterwards to isolate just the Full Moon that occurred immediately before Easter.
The mismatched values
If we look at the summary of the join results, we can see 200 values from Easter Sunday are excluded. This is because the Full Moon dataset only starts in 1900, whereas the Easter Sunday dates go as far back as 1700. Because of this, those Easter Sunday values between 1700 and 1899 are excluded after the join as there's no Full Moon data for those years for them to match against.
Conclusion
Non-equal joins are useful for matching on a condition rather than exact values, but used alone, they can create data inflation problems. Therefore, it might be beneficial to add an equal clause to help optimise a join by reducing the number of comparisons it has to make.

