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 9253143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:08:35+00:00 2026-06-18T11:08:35+00:00

I need some help with a MySQL query. I have this table: Name |

  • 0

I need some help with a MySQL query.

I have this table:

Name  | Date       | City
------+------------+------
Peter | 2013-04-01 | Berlin
Paul  | 2013-03-01 | London
Peter | 2013-03-01 | New York 
Peter | 2013-01-28 | Tokio

I need, for each name, the first date and corresponding city in the table.

I tried:

SELECT Name, MIN(Date) as MD, MIN(City) as CN FROM table GROUP BY Name

But the dates don’t corresponds to the city name, the result was:

Peter, 2013-01-028, Berlin

Can anybody give me a hint?

Thanks

  • 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-06-18T11:08:37+00:00Added an answer on June 18, 2026 at 11:08 am

    You will want to use a subquery to get the min(date) by name and then join that result to your table on both the name and date:

    SELECT t1.Name, 
      t1.Date as MD, 
      t1.City as CN 
    FROM yourtable t1
    inner join
    (
      select min(date) MinDate, name
      from yourtable
      group by name
    ) t2
      on t1.name = t2.name
      and t1.date = t2.mindate
    

    See SQL Fiddle with Demo

    The result is:

    |  NAME |                             MD |     CN |
    ---------------------------------------------------
    |  Paul |   March, 01 2013 00:00:00+0000 | London |
    | Peter | January, 28 2013 00:00:00+0000 |  Tokio |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help optimizing a MySQL query or table When I run this
Need some help with putting this query together. I'm using Mysql I have two
I need some help here. I have a mysql table called dictionary like this:
I need some help with a group by mysql query clause. Medals Table (this
I need some help with a MySQL query I'm working on. I have data
I need some help with a MySQL query. I have two tables, one with
I need some help creating a query for my mySQL database. I have recently
I'm a noob with mysql and php, and need some help :) I have
Need some help to solve this. I have a gridview and inside the gridview
I have a query checking some data in a table (name and a number

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.