Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql connection query examples of left connection, right connection and inner connection

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you about the mysql connection query left connection, right connection, inner connection example, I hope you will get something after reading this article, let's discuss it together!

1. Common mysql connections

INNER JOIN (inner join, or equivalent join): gets the record of the matching relationship between the fields in two tables.

LEFT JOIN (left join): gets all the records in the left table, even if there are no matching records in the right table.

RIGHT JOIN (right join): contrary to LEFT JOIN, it is used to get all the records in the right table, even if there is no corresponding matching record in the left table.

Mysql > select * from name_address;+----+ | address | name | id | +-+ | Northwest Road | Zhang San | 1 | | Northwest second Road | Lisi | 2 | | Northwest third Road | Wang Wu | 3 | +-+ 3 rows in setmysql > select * from name_age +-+ | age | name | id | +-+ | 18 | Zhang San | 1 | 20 | Wang Wu | 2 | 21 | passerby A | 3 | +-+ 3 rows in set

1 、 INNER JOIN

INNER JOIN is consistent with general connected table queries, even though they are separated by commas.

Mysql > SELECT a.`name`, a.ageMagi b.address FROM name_age an INNER JOIN name_address b WHERE (on) a.`name` = b.`name` +-+ | name | age | address | +-+ | Zhang San | 18 | Northwest Road | | Wangwu | 20 | Northwest third Road | +-+ 2 rows in set

2 、 LEFT JOIN

Subject to the data table on the left

Mysql > SELECT a.`name`, a.ageMagi b.address FROM name_age a left JOIN name_address b on a.`name` = b.`name` +-+ | name | age | address | +-+ | Zhang San | 18 | Northwest Road | | Wang Wu | 20 | Northwest No.3 Road | | passerby A | 21 | NULL | +-+ 3 rows in set

3 、 RIGHT JOIN

Contrary to LEFT JOIN, that is, the data on the right shall prevail.

Mysql > SELECT b.`name`, a.agemae b.address FROM name_age a right JOIN name_address b on a.`name` = b.`name` +-+ | name | age | address | +-+ | Zhang San | 18 | Northwest Road | | Wang Wu | 20 | Northwest third Road | | Lisi | NULL | Northwest second Road | +-+ 3 rows in set has finished reading this article. I believe you have a certain understanding of "mysql connection query left connection, right connection, inner connection example". If you want to know more about it, welcome to follow the industry information channel, thank you for your reading!

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report