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.
|119||La Roche||27||44000||67, rue chimay|
|121||Baane mini||32||4110||Ering Shakkes|
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;
|10325||Baane Mini||4110||Ering 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.