夏期劇場 夏期劇場 - 1 month ago 8
MySQL Question

MYSQL SELECT : How to include a field from another table?

In MYSQL, let's say I have following two tables.

"profile":

fullname | gender | country_code
-----------------------------------
Alex | M | us
Benny | M | fr
Cindy | F | en


"country":

country_code | country_name
-----------------------------
jp | Japan
us | United States of America
fr | France
sg | Singapore
en | United Kingdom


When I
SELECT
from the
"profile"
table perspective, how to get the results like below:

WHERE fullname = 'Cindy'


Then:

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

Answer Source

Try the following:

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