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

The sql statement to realize the left join query of three tables

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

Share

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

This article introduces the relevant knowledge of "realizing the sql statement of three-table left join query". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Today we are going to query all the username,psw,gname,tel of realname

Table structure:

Table T1

Field name: T1 accounid.username.psw.

Table T2

Field name: T2 t2_id ID / / one t2_id corresponds to one t2_id

T3

Field name: t _ 3 _ t1_id _ realname _

The trouble encountered is that when a realname has no content in the T2 table, it should also display the username,psw,tel of the realname and directly use the

Sql= "select username,psw,gname,tel from T1, T2 and T3 where t1.t1_id=t2.t1_id and t1.t1_id=t3.t1_id"

The result is that there must be some realname's work in the T2 table to query his information, which is definitely not the desired result. Finally, when you think of using the left join, the sql statement is:

Sql= "select username,psw,gname,tel from (T1 left join T2 on t1.t1_id=t2.t1_id) left join T3 on t1.t1_id=t3.t1_id"

So we get the results we want.

This is the end of the content of "sql statement to realize the left join query of three tables". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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