What is JOIN in SQL?

You can use the SQL JOIN command to gather data from two different tables into a single, merged display table that includes these tables’ included columns. You should generally JOIN tables using one or more factors or values to identify them and try again.

You can join two different tables together. The condition in the first table is evaluated for each row in the second table and, if it matches the condition, the row

Let’s say that you have a database of customer information in a table called Customer_Info.

Every time you sell a product to a customer, you record the Customer Number, Product ID, Price, and Amount Paid for that customer.

The details of orders that are placed on the gateway by the customer are stored in another table called the orders table, which contains the Order Number, Order Date, Expected Shipping Date, and Customer Number.

Imagine that a customer places an order and the following thing that you need to find out is its delivery address.

Although the table only displays customer number data, you can use other column names such as “Customer_Number” and “Product_ID” to order

Join the tables Customers and Order_Number products based on the customer’s number information is necessary. To retrieve the customer’s address, you must use the JOIN

In this specific case, the Customer_Number column is used to compare values.

Customer_NumberCustomer_NameAgePostal_CodeAddress
103Atelier 274400054, RueRoyal
112Signal 32830308489 Strong
114Collector 273004636 Kilda
119La Roche 274400067, rue chimay
121Baane mini 324110Ering Shakkes
customers
Order_NumberOrder_DateExpected_Shipping_DateCustomer_Number
1034531-01-202210-02-2022103
1034630-01-202215-02-2022112
1012005-02-202216-02-2022114
1032506-02-202210-02-2022121
1121108-02-202221-02-20224110
orders

Use the query shown here to connect all of the order numbers to customer names and addresses:

SELECT
  a.Order_Number,
  b.Customer_Name,
  b.Postal_Code,
  b.Address
FROM orders a
JOIN customers b 
ON a.Customer_Number = b.Customer_Number;

Result:

Order_NumberCustomer_NamePostal_CodeAddress
10345Atelier4400054, RueRoyal
10346Signal830308489 Strong
10120Collectors3004636 Kilda
10325Baane Mini4110Ering Shakkes

Here’s how you would use JOIN to combine multiple tables into one. In this query, SQL uses Customer_Number as the JOIN condition. For each order, the matching customer number from orders is compared to the customer number in the customers table. The customer name, postal code, and address are retrieved from that order.