Uploaded image for project: 'Phoenix'
  1. Phoenix
  2. PHOENIX-160

ORDER BY with LIMIT evaluated in wrong order

    XMLWordPrintableJSON

Details

    • Task
    • Status: Resolved
    • Resolution: Fixed
    • None
    • None
    • None
    • 29

    Description

      Using the stock symbol example, if we do these queries:

      ```sql
      SELECT SYMBOL FROM STOCK_SYMBOL ORDER BY SYMBOL DESC LIMIT 3;
      SELECT SYMBOL FROM STOCK_SYMBOL ORDER BY SYMBOL ASC LIMIT 3;
      ```

      One would expect different symbols in each set. Instead we get this result:

      ```
      SYMBOL
      ----------
      GOOG
      CRM
      AAPL
      SYMBOL
      ----------
      AAPL
      CRM
      GOOG
      ```

      Which implies that the LIMIT was applied first, then ORDER BY. I could be wrong but I believe most databases would not evaluate these expressions in that order.

      Attachments

        Activity

          People

            Unassigned Unassigned
            psybers Robert Dyer
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: