In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use table joins in MySQL and PHP. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Table join
A table join (JOIN) is a join condition between multiple tables. Correlate tables so that data can be obtained from multiple tables.
Table join syntax:
SELECT table name 1. Column name, table name 2. Column name FROM Table 1, Table 2 WHERE condition
Several ways to join tables:
Internal connection: join or inner join
Self-join: connections in the same table
External connection:
Left outside connection, left join
Right outer connection, right join
Full external connection, full join
Data (table1)
Data (table2)
Internal connection
An inner join deletes all rows from the result table that do not match the other joined tables. (intersection)
Format:
SELECT A.c1, B.c2 FROM A JOIN B ON A.c3 = B.c3
Example:
Output result:
Database link successful
The SQL statement was executed successfully!
Array
(
[name] = > Yang Fugui
[age] = > 18
[class] = > math class
)
Array
(
[name] = > Yang Mei
[age] = > 19
[class] = > Chinese course
)
Array
(
[name] = > Yang Jianguo
[age] = > 20
[class] = > English course
)
Left connection
Contains all rows that make the table (regardless of whether there are matching rows in the right table), and all matching rows in the right table.
Format:
SELECT A.c1, B.c2 FROM A LEFT JOIN B ON A.c3 = B.c3
Example:
Output result:
Database link successful
The SQL statement was executed successfully!
Array
(
[name] = > Yang Fugui
[age] = > 18
[class] = > math class
)
Array
(
[name] = > Yang Mei
[age] = > 19
[class] = > Chinese course
)
Array
(
[name] = > Yang Jianguo
[age] = > 20
[class] = > English course
)
Array
(
[name] > Yang Tiezhu
[age] = > 21
[class] = >
)
Right connection
Contains all rows of the right table (regardless of whether there are matching rows in the left table) and all matching rows in the left table.
Format:
SELECT A.c1, B.c2 FROM A RIGHT JOIN B ON A.c3 = B.c3
Example:
Output result:
Database link successful
The SQL statement was executed successfully!
Array
(
[name] = > Yang Fugui
[age] = > 18
[class] = > math class
)
Array
(
[name] = > Yang Mei
[age] = > 19
[class] = > Chinese course
)
Array
(
[name] = > Yang Jianguo
[age] = > 20
[class] = > English course
)
Array
(
[name] = >
[age] = >
[class] = > History course
)
Full connection
Contains all rows of the left and right tables (regardless of whether there is a matching row in the other table or not).
Format:
SELECT A.c1, B.c2 FROM A LEFT JOIN B ON A.c3 = B.c3
UNION
SELECT A.c1, B.c2 FROM A RIGHT JOIN B ON A.c3 = B.c3
Example:
Output result:
Database link successful
The SQL statement was executed successfully!
Array
(
[name] = > Yang Fugui
[age] = > 18
[class] = > math class
)
Array
(
[name] = > Yang Mei
[age] = > 19
[class] = > Chinese course
)
Array
(
[name] = > Yang Jianguo
[age] = > 20
[class] = > English course
)
Array
(
[name] > Yang Tiezhu
[age] = > 21
[class] = >
)
Array
(
[name] = >
[age] = >
[class] = > History course
)
Thank you for reading! This is the end of this article on "how to use table joins in MySQL and PHP". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un