Generally speaking, in order to get more complete results, we need to get results from two or more tables. I usually use select xxx,xxx from table1, table2 where table1.xxx=table2.xxx. We usually perform such operations. In fact, there is another operation in MySQL, that is, join operation. For example, there are two tables below: Take a look at the "Persons" table: Next, look at the "Orders" table: The above two tables, then we connect them to query SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo FROM Persons, Orders WHERE Persons.Id_P = Orders.Id_P Result Set: If you use the keyword JOIN to get data from two tables SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo FROM Persons INNER JOIN Orders ON Persons.Id_P = Orders.Id_P ORDER BY Persons.LastName Result Set: Then the inner join is no different from the normal query above Different SQL JOINs
LEFT JOIN Keyword Syntax "Persons" table: "Orders" table: SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo FROM Persons LEFT JOIN Orders ON Persons.Id_P=Orders.Id_P ORDER BY Persons.LastName Result Set: SQL RIGHT JOIN Keyword "Persons" table: "Orders" table: SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo FROM Persons RIGHT JOIN Orders ON Persons.Id_P=Orders.Id_P ORDER BY Persons.LastName Result Set: SQL FULL JOIN keyword "Persons" table: "Orders" table: FULL JOIN Example SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo FROM Persons FULL JOIN Orders ON Persons.Id_P=Orders.Id_P ORDER BY Persons.LastName Result Set: Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links You may also be interested in:
|
<<: Implementation of React configuration sub-routing
>>: Detailed explanation of basic management of KVM virtualization in CentOS7
Table of contents Demand background Thought Analy...
Learning Linux commands is the biggest obstacle f...
Copy code The code is as follows: .sugLayerDiv{ p...
Table of contents Example Method 1: delete Method...
We often see ads appear after a few seconds and t...
Recently, I encountered a problem in the process ...
The installation of Harbor is pretty simple, but ...
This article records the installation and configu...
1 Cause After the project migrated the database a...
Table of contents 1. How to view the binary data ...
Preface As we all know, everything in Linux is a ...
Due to your company standards, you may only allow...
#docker ps check, all ports are mapped CONTAINER ...
name character name character information news te...
Configure multiple servers in nginx.conf: When pr...