MYSQL SELECT WHERE子句:如何包含另一个表中的列?

夏期劇*_*期劇場 1 mysql select include

在MYSQL中,假设我有两个表.

"轮廓":

fullname | gender | country_code
-----------------------------------
Alex     | M      | us
Benny    | M      | fr
Cindy    | F      | uk
Run Code Online (Sandbox Code Playgroud)

"国家":

country_code | country_name
-----------------------------
jp           | Japan
us           | United States of America
fr           | France
sg           | Singapore
uk           | United Kingdom
Run Code Online (Sandbox Code Playgroud)

"profile"表的角度查询时,如下所示:

WHERE fullname = 'Cindy'
Run Code Online (Sandbox Code Playgroud)

然后在结果中,我如何包含另一个表中的列(以获得如下所示的结果):

fullname | gender | country_code | country_name
------------------------------------------------
Cindy    | F      | uk           | United Kingdom
Run Code Online (Sandbox Code Playgroud)

Nap*_*ter 5

您可以使用

select a.fullname, a.gender, b.country_code, b.country_name 
FROM profile a 
LEFT JOIN country b ON a.country_code = b.country_code 
WHERE a.fullname='Cindy'
Run Code Online (Sandbox Code Playgroud)