SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php distinct year

    hi.. i am just wondering how to select DISTINCT all the YEARS in a dateTime field. the data in the table looks like this.


    ID, datetime, eventName
    1, 2008-12-01 01:10:20, test 1
    2, 2007-12-01 01:10:20, test 2
    3, 2008-12-01 01:10:20, test 3
    4, 2006-12-01 01:10:20, test 4
    5, 2008-12-01 01:10:20, test 5
    6, 2007-12-01 01:10:20, test 6


    i would like to return the following:

    ID, datetime, eventName
    1, 2008-12-01 01:10:20, test 1
    4, 2006-12-01 01:10:20, test 4
    6, 2007-12-01 01:10:20, test 6

    does that make any sense at all??

    many thanks in advance

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    Code SQL:
    SELECT ID, YEAR(datetime) YEAR, datetime, eventName FROM YourTable GROUP BY YEAR(datetime)

    Year should hold the year in question, if you want it.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow thanks for the quick response... it worked perfectly!


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
  •