SQL Order By issue with UNION -
i have 2 sql queries using union.
select studentid student union select coursename course; if want order result coursename, how can that?
if try following gives me error.
select studentid student union select coursename course order coursename ;
first of columns have same in both unified select's. i'm not sure, doesn't in case (because of studentid , coursename - sounds number , varchar).
however, if that's case, put sub-select , sort result:
select * (select studentid col student union select coursename col course) order col; p.s. stephan pointed out correctly don't need sub select here:
select studentid col student union select coursename col course order col; reason way how union works.
p.p.s. see fiddles here: oracle , mysql.
please note: as typical mysql. if use oracle remove it.
cheers!
Comments
Post a Comment