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

MYSQL SELECT WHERE子句:如何包含另一个表中的列?,mysql,select,include,Mysql,Select,Include,在MYSQL中,假设我有以下两个表 简介: fullname | gender | country_code ----------------------------------- Alex | M | us Benny | M | fr Cindy | F | uk 国家: country_code | country_name ----------------------------- jp | Japan us

在MYSQL中,假设我有以下两个表

简介:

fullname | gender | country_code
-----------------------------------
Alex     | M      | us
Benny    | M      | fr
Cindy    | F      | uk
国家:

country_code | country_name
-----------------------------
jp           | Japan
us           | United States of America
fr           | France
sg           | Singapore
uk           | United Kingdom
从概要表的角度进行查询时,如下所示:

WHERE fullname = 'Cindy'
那么在结果中,我如何从另一个表中包含一列以获得如下结果:

fullname | gender | country_code | country_name
------------------------------------------------
Cindy    | F      | uk           | United Kingdom

你需要加入表格。例如:

select a.fullname, a.gender, b.country_code, b.country_name 
  from profile a JOIN country b 
    on a.country_code = b.country_code 
 where a.fullname='Cindy'

你需要加入表格。例如:

select a.fullname, a.gender, b.country_code, b.country_name 
  from profile a JOIN country b 
    on a.country_code = b.country_code 
 where a.fullname='Cindy'
您应该使用“加入”:

选择配置文件。*,country.country\u名称 来自客户 内部联接顺序 在配置文件上.country\u代码=country.country\u代码 有关更多信息,请检查此项:

您应该使用“加入”:

选择配置文件。*,country.country\u名称 来自客户 内部联接顺序 在配置文件上.country\u代码=country.country\u代码 有关更多信息,请检查此项:

尝试此项

SELECT t1.fullname, t1.gender t1.country_code,t2.country_name
FROM profile AS t1 INNER JOIN country AS t2 ON t1.country_code = t2.country_code where t1.fullname='cindy';
试试这个

SELECT t1.fullname, t1.gender t1.country_code,t2.country_name
FROM profile AS t1 INNER JOIN country AS t2 ON t1.country_code = t2.country_code where t1.fullname='cindy';
你可以用

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'
你可以用

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'
请尝试以下操作:

Select * from profile natural join country where fullname='Cindy'
请尝试以下操作:

Select * from profile natural join country where fullname='Cindy'

您需要在配置文件和国家/地区表之间使用联接,如下所示

SELECT
profile.fullname,
profile.gender, 
country .country_code, 
country .country_name 
FROM profile as profile JOIN country as country 
       ON (profile.country_code = country.country_code)
  WHERE profile.fullname = 'Cindy'

您需要在配置文件和国家/地区表之间使用联接,如下所示

SELECT
profile.fullname,
profile.gender, 
country .country_code, 
country .country_name 
FROM profile as profile JOIN country as country 
       ON (profile.country_code = country.country_code)
  WHERE profile.fullname = 'Cindy'

我相信其他答案也不错。但是这个已经足够好了,而且很简单。谢谢。我相信其他答案也不错。但是这个已经足够好了,而且很简单。谢谢