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
Recorded the download and installation tutorial o...
By chance, I discovered that a SQL statement prod...
Step 1: Use Notepad to open the "my.ini"...
touch Command It has two functions: one is to upd...
Method 1: Use cmd command First, open our DOS win...
1. Prerequisites We use the require.context metho...
When making a form in a recent project, I need to...
MySQL deduplication methods 【Beginner】There are v...
Network type after docker installation [root@insu...
Serve: # chkconfig --list List all system service...
Angular Cookie read and write operations, the cod...
There are many scripts on the Internet that use e...
The content of the written Dockerfile is: FROM py...
This article uses examples to illustrate the use ...
Password Mode PDO::__construct(): The server requ...