faster query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bunnytail

    #1

    faster query



    Hi all,

    I have a table with a field of datetime (0000-00-00 00:00:00), in order
    to get a unique list of what are the years available in the database
    records, I use:

    Select YEAR(datetime) from data group by YEAR(datetime);

    which returns:
    ------------------
    | YEAR(datetime) |
    -------------------
    | 1998|
    | 1999|
    | 2000|
    | 2001|
    | 2002|
    | 2003|
    | 2004|
    |------------------|
    7 rows in set (2.59 sec)


    There are total of 44251 rows in the data table. Is there a better way
    to get the year list?

    Thanks in advance,

    sheng

  • W. Davis

    #2
    Re: faster query

    index the field

    "bunnytail" <nospam@spam.co m> wrote in message
    news:401003BD.4 080405@spam.com ...[color=blue]
    >
    >
    > Hi all,
    >
    > I have a table with a field of datetime (0000-00-00 00:00:00), in order
    > to get a unique list of what are the years available in the database
    > records, I use:
    >
    > Select YEAR(datetime) from data group by YEAR(datetime);
    >
    > which returns:
    > ------------------
    > | YEAR(datetime) |
    > -------------------
    > | 1998|
    > | 1999|
    > | 2000|
    > | 2001|
    > | 2002|
    > | 2003|
    > | 2004|
    > |------------------|
    > 7 rows in set (2.59 sec)
    >
    >
    > There are total of 44251 rows in the data table. Is there a better way
    > to get the year list?
    >
    > Thanks in advance,
    >
    > sheng
    >[/color]


    Comment

    Working...