Interesting comment.

I find by experiment that
  (select * from FOO order by a desc limit 10) order by a;
removes duplicates, but, if I drop the second order clause,
  (select * from FOO order by a desc limit 10);
duplicates are retained.

Why is the first a union, but not the second?  Just curious.

> From: "Keith C. Ivey" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Date: Fri, 23 Apr 2004 11:27:38 -0400
> Subject: Re: first LIMIT then ORDER

> On 23 Apr 2004 at 7:23, Bill Easton wrote:

> > The last suggestion is useful when you do care which entries you get,
> > as you can use one order for limit and another for presentation. For
> > example, if you'd like the LAST 10 rows, but sorted in FORWARD order,
> > you can use something like
> > 
> >     (select * from HISTORY order by version desc limit 10) order by
> >     version;
> > 
> > And I thought I'd have to wait for subqueries...

> One small gotcha that Anders Karlsson pointed out to me through Paul 
> DuBois:  This one-query union syntax doesn't allow you to use the ALL 
> keyword after UNION (since the UNION keyword isn't even there).  That 
> means it will always eliminate duplicate rows (like DISTINCT).  That 
> hasn't come up when I've used it, since I've never been selecting 
> result sets that could contain duplicate rows, but it's something to 
> keep in mind.

> -- 
> Keith C. Ivey <[EMAIL PROTECTED]>
> Tobacco Documents Online
> http://tobaccodocuments.org


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to