1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

MySQL group by in text type date field

Discussion in 'MySQL' started by Alam, May 15, 2010.

  1. #1
    Dear All,

    I have some records with a datetime field. datetime filed type is varchar. So, how can I use group by command to group by date (not datetime).

    sample records:

    name---------Class---------date
    Alam---------xxx-----------20100515041145
    Selim---------xxx-----------20100515041155
    Sohel---------xxx-----------20100615041202

    I need to getting records by grouping date (i.e. 20100515 and 20100516)

    so, what will be query???? :confused:

    Please help :(

    Thanks advance.
     
    Alam, May 15, 2010 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    I'm assuming the date column is an int, char or varchar and not a datetime type, this should be the most efficient way to do it.

    GROUP BY LEFT(`date`,8)
     
    jestep, May 15, 2010 IP
    Alam likes this.