Home > Backend Development > PHP Tutorial > Related knowledge about SQL JOIN

Related knowledge about SQL JOIN

jacklove
Release: 2023-03-25 15:32:01
Original
2505 people have browsed it

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
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template