Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get name from another table when using a key in SELECT?

I know this may be an easy question, but I've been stumped on this for the past hour and am not sure what terms to lookup that accurately describe what I am trying to do.

I have a MySQL database with two tables. Countries and Regions. The Regions table has two columns, id and name. An example of a row would be 1, north-america.

In the Countries table, there's a column named RegionID that would have a 1 if the country's region is north-america.

How can I grab the "north-america" in my query instead of printing out "1"?

Here's my SELECT that I am stumped on:

SELECT A.name, A.regionID FROM countries A, regions B ORDER BY A.name ASC
like image 769
Stevo Avatar asked Dec 29 '25 07:12

Stevo


1 Answers

SELECT A.name, A.regionID, b.Name
FROM countries A
   Join regions B 
      on B.id = A.RegionId
ORDER BY A.name ASC
like image 146
Charles Bretana Avatar answered Dec 30 '25 21:12

Charles Bretana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!