SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to get the youngest policeman

    Hello

    Given the following table definition, I would like to obtain the ID of the younger policeman and his birth date:
    Code:
    CREATE TABLE `people` (
      `Person_ID` int unsigned not null,
      `Job` varchar not null,
      `Birthdate` datetime not null,
      PRIMARY KEY  (`Person_ID`)
    ) ENGINE=MyISAM default charSET=latin1;
    here was my unsuccessful attempt:
    Code:
    SELECT Person_ID, Birthdate
    FROM people
    WHERE Birthdate >= (
        SELECT Birthdate
        FROM people
        WHERE Job = 'Policeman');
    Any help would be appreciated

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    New Castle, PA
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my untested answer would be:

    SELECT Person_ID, MIN(Birthdate)
    FROM people
    WHERE Job = 'Policeman'
    GROUP BY Person_ID;

  3. #3
    SitePoint Addict Fire59's Avatar
    Join Date
    Aug 2003
    Location
    mn
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT Pserson_ID, Birthdate FROM people WHERE Job='Policeman' ORDER BY Birthdate ASC LIMIT 1
    This should select the youngest policeman by birthdate.

  4. #4
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reponses
    I will use your suggestions


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •