List:General Discussion« Previous MessageNext Message »
From:Rick James Date:June 22 2012 12:58am
Subject:RE: UNION and ORDER BY
View as plain text  
The parens are for making sure the parsing works correctly.  Probably either one works
fine.  Suggest you do
  EXPLAIN EXTENDED ...;
  SHOW WARNINGS;
I suspect that the output from each will be identical, and have more parens.

The main need for parens is to avoid associating the ORDER BY with just the second SELECT.

> -----Original Message-----
> From: Hal?sz S?ndor [mailto:hsv@stripped]
> Sent: Thursday, June 21, 2012 4:07 PM
> To: mysql@stripped
> Subject: UNION and ORDER BY
> 
> >>>> 2012/06/20 14:32 -0700, Rick James >>>>
> (
>    SELECT ruid1, ruid2, overlap FROM l4_link WHERE ruid1=xxx
>    UNION
>    SELECT ruid1, ruid2, overlap FROM l4_link WHERE ruid2=xxx
> ) ORDER BY overlap DESC;
> 
> Make it UNION ALL or UNION DISTINCT depending on whether xxx can be in
> both fields of one row.  UNION DISTINCT makes a pass over the temp
> table to dedup.
> <<<<<<<<
> The help example shows a UNION s each SELECT separatly round-bracketed,
>     (SELECT ruid1, ruid2, overlap FROM l4_link WHERE ruid1=xxx)
>     UNION
>     (SELECT ruid1, ruid2, overlap FROM l4_link WHERE ruid2=xxx)
>   ORDER BY overlap DESC
> but bracketing both is not mentioned. What is the difference?
> 
> 
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql

Thread
Indexing about 40 Billion EntriesChristian Koetteritzsch20 Jun
  • Re: Indexing about 40 Billion EntriesAnanda Kumar20 Jun
    • RE: Indexing about 40 Billion EntriesRick James20 Jun
      • Re: Indexing about 40 Billion EntriesChristian Koetteritzsch20 Jun
        • Re: Indexing about 40 Billion EntriesChristian Koetteritzsch20 Jun
        • RE: Indexing about 40 Billion EntriesRick James20 Jun
          • Re: Indexing about 40 Billion EntriesChristian Koetteritzsch21 Jun
            • Re: Indexing about 40 Billion Entriesmos21 Jun
              • Re: Indexing about 40 Billion EntriesChristian Koetteritzsch21 Jun
              • RE: Indexing about 40 Billion EntriesRick James21 Jun
          • UNION and ORDER BYhsv22 Jun
            • RE: UNION and ORDER BYRick James22 Jun
  • Re: Indexing about 40 Billion EntriesShawn Green20 Jun
    • RE: Indexing about 40 Billion EntriesRick James20 Jun
  • Re: Indexing about 40 Billion EntriesBrent Clark21 Jun