Subject | Re: Valid reasons for sorting on a column one doesn't select? - a BUG! |
---|---|
Author | Adam |
Post date | 2005-08-14T23:35:09Z |
>though
> However, it's a stretch to call it a "bug" to allow the query which,
> silly, does no harm. Ordering is logically *possible*, even if's notit
> sensible to anticipate that it will be meaningful to most people, and
> breaks nothing. If someone wants to do something like that, whyshould the
> engine prevent them?Absolutely right! (And a nice little experiment btw)
>
Providing the FB implementation meets the SQL standard, it should not
prevent them from being run.
As an aside, this is an example of where such a query is useful in our
system.
select First 50 EmployeeID
from EmployeeChanges
where DeviceID = ?
order by ChangeTime
Basically we have a notification table for an offsite database that
fills itself using triggers. This statement will return the oldest
change that device needs to know about (or null if there are no
changes). Of course an index on DeviceID, ChangeTime lets it run
lightning fast. I do not care when the change time was, I just want to
process them in order, and do not want to fill my pipe with non urgent
data.
Other examples are (as other people have posted), storing a display
order field in your table. Why return it if you have no interest in the
value itself?
Adam