Feature image SQL Join on Multiple Columns 101

SQL Join on Multiple Columns 101: The Easy Way vs The Hard Way

By Laurent Maurer · October 26, 2022 · 4 min read

Difficulty Level: Expert

In this article, we will discuss how to use SQL Join on multiple columns.

This function is a built-in operation used for working on several tables.

Let’s dive into how to use it in both Code & No Code.

SQL Join on Multiple Columns: The Easy Way Without Coding

1. Dataset

Let’s take a look at the following MongoDB Sample Datasets (Use our Public Sample Datasets for free).

2. Syntax:

  • Step 1: Search and drag and drop the Join function in the sidebar: 
  • Step 2: Select in the dropdown list, the Join type you want to operate:
  • Step 3: Click on the “+” button as many times as required to join on multiple columns (in the example below, we have a pair of matching columns):

3. Example:

Input: 

Output: 

SQL Join on Multiple Columns: The Hard Way With Code

To reproduce the same output as above but with code, you need to write the following query:

Input:

				
					SELECT account_id, account_id,
       transactions_symbol, products
FROM accounts
INNER JOIN transactions
ON account_id.accounts =account_id.transactions
AND  transactions_symbol.transactions = products.accounts

				
			

The more you want to join on multiple columns the longer your SQL query will be. Your SQL query won’t be optimized this way and less and less readable for any data practitioner.

Conclusion

At RestApp, we’re building a Data Activation Platform for modern data teams with our large built-in library of connectors to databases, data warehouses and business apps.

We have designed our next-gen data modeling editor to be intuitive and easy to use.

If you’re interested in starting with connecting all your favorite tools, check out the RestApp website or try it for free with a sample dataset.

Discover the next-gen end-to-end data pipeline platform with our built-in No Code SQL, Python and NoSQL functions. Data modeling has never been easier and safer thanks to the No Code revolution, so you can simply create your data pipelines with drag-and-drop functions and stop wasting your time by coding what can now be done in minutes! 

Play Video about Analytics Engineers - Data Pipeline Feature - #1

Discover Data modeling without code with our 14-day free trial!

Category

Share

Subscribe to our newsletter

Laurent Mauer
Laurent Mauer
Laurent is the head of engineer at RestApp. He is a multi-disciplinary engineer with experience across many industries, technologies and responsibilities. Laurent is at the heart of our data platform.

Related articles

Build better data pipelines

With RestApp, be your team’s data hero by activating insights from raw data sources.