Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7610929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:32:16+00:00 2026-05-31T01:32:16+00:00

My MySQL table country_phone_codes looks something like this id country_code area_code name ———————————————————— 1

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:32:18+00:00Added an answer on May 31, 2026 at 1:32 am

    The answer is trivial, using GROUP BY:

    SELECT country_code,MIN(name)
    FROM country_phone_codes
    GROUP BY country_code;
    

    The DISTINCT function and ORDER BY aren’t necessary with GROUP BY. As the original question specifically pertained to MySQL, the MIN() aggregate function isn’t necessary and you might see better performance without it if all of the following are true:

    • The server is MySQL
    • The storage engine is InnoDB
    • The first column of the example data is the primary key and the entries follow the same ordering suggested by the small sample, namely, the country name appears before all other names in the group.

    This works because the InnoDB storage engine will scan in the order of the primary key and, for nonaggregated columns, it will use the first value it finds.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql table that looks something like this: Row 1: 'visitor_input_id' =>
I have a mysql table with data like (name, address, sex, city state, zip,
This is the MySQL table structure that I have: itemID (BIGINT) userID (BIGINT) wasAdded
I have a mysql database table to store country name and currency symbol -
I have this table in mySQL intended to map some values to other values,
I tried this in mysql: mysql> alter table region drop column country_id; And got
Mysql: Table_A ------------ id name 1 Name1 2 Name2 Table_B ------------ a_id type value
My MySQL table is simple. I have 3 fields: an index a url a
Consider an indexed MySQL table with 7 columns, being constantly queried and written to.
I have a MySQL table with approximately 3000 rows per user. One of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.