From: Rick James Date: June 22 2012 12:58am Subject: RE: UNION and ORDER BY List-Archive: http://lists.mysql.com/mysql/227728 Message-Id: <2E7DD7ADE53B044C8C8BCD9C5829E1EB1487608302@SP2-EX07VS01.ds.corp.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable The parens are for making sure the parsing works correctly. Probably eithe= r 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 >=20 > >>>> 2012/06/20 14:32 -0700, Rick James >>>> > ( > SELECT ruid1, ruid2, overlap FROM l4_link WHERE ruid1=3Dxxx > UNION > SELECT ruid1, ruid2, overlap FROM l4_link WHERE ruid2=3Dxxx > ) ORDER BY overlap DESC; >=20 > 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=3Dxxx) > UNION > (SELECT ruid1, ruid2, overlap FROM l4_link WHERE ruid2=3Dxxx) > ORDER BY overlap DESC > but bracketing both is not mentioned. What is the difference? >=20 >=20 > -- > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe: http://lists.mysql.com/mysql