--- a/sql/sql_yacc.yy	Sat Apr  7 12:23:32 2007
+++ b/sql/sql_yacc.yy	Mon Apr 16 12:29:39 2007
@@ -6134,7 +6134,8 @@
           SELECT_LEX *sel= lex->current_select;
           SELECT_LEX_UNIT *unit= sel-> master_unit();
 	  if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
-	      sel->olap != UNSPECIFIED_OLAP_TYPE)
+              sel->olap != UNSPECIFIED_OLAP_TYPE
+              && !( sel->linkage == UNION_TYPE &&  !sel->braces ))
 	  {
 	    my_error(ER_WRONG_USAGE, MYF(0),
                      "CUBE/ROLLUP", "ORDER BY");
--- a/mysql-test/t/union.test	Wed Mar 21 18:53:51 2007
+++ b/mysql-test/t/union.test	Mon Apr 16 12:35:25 2007
@@ -878,3 +878,22 @@
 --error 1172
 (select 2) union (select 1 into @var);
 --echo End of 5.0 tests
+
+#
+#Bug#27848: order-by of union clashes with rollup of select part
+#
+
+create table t1 (a int);
+insert into t1 values (10), (20);
+create table t2 (b int);
+insert into t2 values (5), (50), (50);
+
+select a,1 from t1 UNION select b, count(*) from t2 group by b with rollup order by a;
+select a,1 from t1 UNION select b, count(*) from t2 group by b with rollup order by a desc;
+select a,1 from t1 UNION select b, count(*) from t2 group by b with rollup order by a desc limit 3;
+select a,1 from t1 UNION ALL select b, count(*) from t2 group by b with rollup order by a desc;
+
+--error 1221
+select a,1  from t1 UNION ALL select b, count(*) from t2 group by b with rollup order by a UNION select 1,1;
+
+drop table t1,t2;
--- a/mysql-test/r/union.result	Thu Mar 22 13:58:37 2007
+++ b/mysql-test/r/union.result	Mon Apr 16 12:35:38 2007
@@ -1390,3 +1390,36 @@
 (select 2) union (select 1 into @var);
 ERROR 42000: Result consisted of more than one row
 End of 5.0 tests
+create table t1 (a int);
+insert into t1 values (10), (20);
+create table t2 (b int);
+insert into t2 values (5), (50), (50);
+select a,1 from t1 UNION select b, count(*) from t2 group by b with rollup order by a;
+a      1
+NULL   3
+5      1
+10     1
+20     1
+50     2
+select a,1 from t1 UNION select b, count(*) from t2 group by b with rollup order by a desc;
+a      1
+50     2
+20     1
+10     1
+5      1
+NULL   3
+select a,1 from t1 UNION select b, count(*) from t2 group by b with rollup order by a desc limit 3;
+a      1
+50     2
+20     1
+10     1
+select a,1 from t1 UNION ALL select b, count(*) from t2 group by b with rollup order by a desc;
+a      1
+50     2
+20     1
+10     1
+5      1
+NULL   3
+select a,1  from t1 UNION ALL select b, count(*) from t2 group by b with rollup order by a UNION select 1,1;
+ERROR HY000: Incorrect usage of UNION and ORDER BY
+drop table t1,t2;
