selecting in reverse order

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

    #1

    selecting in reverse order

    I am doing a simple query like col1, col2, date, col4 from table1.
    All four colums are of type blob. For date column, I store a string
    like this:

    Fri Feb 13 11:01:24 2004

    I store records as they come in so the oldest record is at the top of
    the table. When I select and display, I want to display them in
    reverse order (newest record at the top) but I can't sort on date with
    strings like that.

    Is there any way to do this w/o changing my column types or creating a
    temporary table? I guess I can store all the rows temporarily in a
    variable and print them out in reverse order but that's not an option.
    I am looking a SQL way to accomplish this. Thanks.

    -James
  • Aggro

    #2
    Re: selecting in reverse order

    James Lee wrote:
    [color=blue]
    > I store records as they come in so the oldest record is at the top of
    > the table.[/color]

    There is no guarantee that they come in that order. You should always
    use "order by" when you want your rows in specific order.
    [color=blue]
    > Is there any way to do this w/o changing my column types or creating a
    > temporary table?[/color]

    You can add a new column to your table. And order rows according to
    that. You can use either id values or timestamp or other column type,
    what ever you prever to use for ordering the rows. You will also need to
    fill your new column with proper values. You could try parsing the date
    string to get the proper values for the new column.

    You can also try parsing your date string to figure out the order of
    rows, but that will be slow.

    Comment

    • Aggro

      #3
      Re: selecting in reverse order

      James Lee wrote:
      [color=blue]
      > I store records as they come in so the oldest record is at the top of
      > the table.[/color]

      There is no guarantee that they come in that order. You should always
      use "order by" when you want your rows in specific order.
      [color=blue]
      > Is there any way to do this w/o changing my column types or creating a
      > temporary table?[/color]

      You can add a new column to your table. And order rows according to
      that. You can use either id values or timestamp or other column type,
      what ever you prever to use for ordering the rows. You will also need to
      fill your new column with proper values. You could try parsing the date
      string to get the proper values for the new column.

      You can also try parsing your date string to figure out the order of
      rows, but that will be slow.

      Comment

      • Aggro

        #4
        Re: selecting in reverse order

        James Lee wrote:
        [color=blue]
        > I store records as they come in so the oldest record is at the top of
        > the table.[/color]

        There is no guarantee that they come in that order. You should always
        use "order by" when you want your rows in specific order.
        [color=blue]
        > Is there any way to do this w/o changing my column types or creating a
        > temporary table?[/color]

        You can add a new column to your table. And order rows according to
        that. You can use either id values or timestamp or other column type,
        what ever you prever to use for ordering the rows. You will also need to
        fill your new column with proper values. You could try parsing the date
        string to get the proper values for the new column.

        You can also try parsing your date string to figure out the order of
        rows, but that will be slow.

        Comment

        Working...