Subject | Re: [firebird-support] distinct query |
---|---|
Author | Helen Borrie |
Post date | 2006-03-23T04:18:54Z |
>At 11:25 AM 23/03/2006, you wrote:At 02:43 PM 23/03/2006, I wrote:
> >Hi everyone,
> > we're having a spot of trouble with a query.
> >
> >As you can see below we're selecting data from a view using distinct and
> >order by...
> >
> >SELECT DISTINCT activity_id, activity_date
> >FROM VIEW_NAME
> >ORDER BY activity_date ASC, activity_label
> >
> >This doesn't return rows ordered by activity_date...
> >
> >Little help?
>Ummm...is activity_label actually a column in the view?Errm, moreover, I neglected to comment that trying to order a
>
>What happens if you either 1) take out activity_label from the order
>by clause or 2) add activity_label to the select list?
DISTINCT query by a column that is not in the DISTINCT spec is
illogical. By its very nature, DISTINCT eliminates all rows that
contain duplicate instances of the value mix specified in the
SELECT. That's what DISTINCT is *designed* for. Any columns not
used for distinguishing which rows are selected are irrelevant and
take no further part in the logic.
The row selected will be the first (in no order) that matches the
DISTINCT specification. The final set of distinct rows will have no
way to relate to any particular activity_label, since it's not
involved in the distinguishing logic.
So work out what you really want in your output and re-cut the cloth.
./heLen