Question: My MySQL table country\_phone\_codes looks something like this

```
id     country_code     area_code     name
------------------------------------------------------------
1   |   93           |  93         |  AFGHANISTAN
2   |   93           |  9370       |  AFGHANISTAN - MOBILE
3   |   93           |  9375       |  AFGHANISTAN - MOBILE
4   |   355          |  355        |  ALBANIA
5   |   355          |  35568      |  ALBANIA - MOBILE - AMC
6   |   213          |  213        |  ALGERIA
7   |   213          |  2131       |  ALGERIA - CAT
------------------------------------------------------------

```

These are just few records of more than 28000 records. I am trying to formulate a query that will provide me with the result like this-

```
country_code    name
-----------------------------
93            |  AFGHANISTAN
355           |  ALBANIA
213           |  ALGERIA
-----------------------------

```

By using `SELECT DISTINCT(country_code) FROM country_phone_codes ORDER BY country_code LIMIT 0,260`, I am able to get distinct country codes. But how do I get corresponding country name?

Answer: 
To select distinct country\_code, name pairs:

```
select country_code, name
from country_phone_codes
where country_code = area_code;

```
As you seem to want to select those rows, where the area\_code is the same as country\_code, you could just select those rows where area\_code and country\_code are equal:

```
SELECT country_code, name
FROM country_phone_codes
WHERE area_code = country_code;

```

If there is possibility that there are multiple rows with the same area code and country code, you can use DISTINCT to select only one row for each (country\_code, name) tuple.

```
SELECT DISTINCT country_code, name
FROM country_phone_codes
WHERE area_code = country_code;

```