Home > Article > Backend Development > Related knowledge about SQL JOIN
SQL JOIN related knowledge is very important for php, this article will explain it.
SQL join is used to query data from two or more tables based on the relationship between columns in these tables.
Join and Key
Sometimes to get complete results, we need to get results from two or more tables. We need to execute join.
Tables in a database can be linked to each other through keys. The primary key (Primary Key) is a column in which the value of each row is unique. In a table, each primary key value is unique. The purpose of this is to cross-bundle data between tables without duplicating all the data in each table.
ReferenceTwo tables
We can get data from the two tables by referencing the two tables:
Who ordered the product , and what products did they order?
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo FROM Persons, Orders WHERE Persons.Id_P = Orders.Id_P
SQL JOIN - Using Join
In addition to the above method, we can also use the keyword JOIN to get data from two tables.
If we want to list everyone’s orders, we can use the following SELECT statement:
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo FROM PersonsINNER JOIN OrdersON Persons.Id_P = Orders.Id_P ORDER BY Persons.LastName
This article explains the relevant knowledge of join. For more learning materials, please pay attention to php Chinese You can watch it online.
Related recommendations:
Explanation on SQL Alias (alias) in php
How to use the SQL BETWEEN operator
How to use the SQL IN operator
The above is the detailed content of Related knowledge about SQL JOIN. For more information, please follow other related articles on the PHP Chinese website!