简体   繁体   English

SQL select语句内部联接

[英]SQL select statement inner join

I hava a table Person and a table Club. 我有一个桌子人和一个桌子俱乐部。

I am using a sql statement to link Person to Club because there is a field PersonclubID that i want to link to the name of the club (ClubName). 我使用sql语句将Person链接到Club,因为有一个我要链接到Club名称(ClubName)的PersonclubID字段。 They are in relation with the ID as you can see in the sql statement. 正如您在sql语句中看到的那样,它们与ID有关。

Now it shows me all the persons who have a clubID but I also want those without one. 现在,它向我显示了所有具有clubID的人,但我也希望没有这些人的人。

statement: 声明:

select * from Person AS p INNER JOIN club AS c ON p.club_id =c.id where isTrainer = false

regards 问候

Use a LEFT JOIN in that case. 在这种情况下,请使用LEFT JOIN It will show you all Person rows and will have values for the Club rows that are matched. 它会显示所有“ Person行,并具有匹配的“ Club行的值。 Rows that do not match will contain NULL values for Club values 不匹配的行将包含Club值的NULL

NB: Experiment with the Joins a bit :) Enjoy it NB:尝试一下加入:)享受它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM