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

Query of MYSQL connected tables and usage of aliases

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

MYSQL connected table query is a query between two tables or more tables, which queries all data by means of foreign keys, resulting in field duplication in the query process. In order to distinguish this situation, database design aliases, some tables are very long, can also use aliases.

1. Join tables to query INNER JOIN, LEFT JOIN,RIGHT JOIN

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.

2, example

Inner chain reads intersecting data

Mysql > SELECT a.huthon_id, a.huthon_author, b.huthon_count FROM huthon_tbl a, tcount_tbl b WHERE a.runoob_author = b.runoob_author

The left side reads the data on the left.

Mysql > SELECT a.huthon_id, a.huthon_author, b.huthon_count FROM runoob_tbl a LEFT JOIN tcount_tbl b ON a.runoob_author = b.runoob_author

The right chain reads the data on the right.

Mysql > SELECT a.huthon_id, a.huthon_author, b.huthon_count FROM runoob_tbl a RIGHT JOIN tcount_tbl b ON a.runoob_author = b.runoob_author

3, the use of aliases

Field huthon_id as A1

Table gdhuthon as huthon

The article is from http://www.huthon.com.

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