
A common problem when using the UNION command in MySQL is when you want to order the sets of data differently. If you do it incorrectly, you will see the error message:
Incorrect usage of UNION and ORDER BY
To solve the problem, wrap each individual SELECT statement in parenthesis as follows:
{code type=php}
(SELECT col1,col2,col3 FROM table1 ORDER BY col2)
UNION
(SELECT cola,colb,colc FROM table2 ORDER BY cola)
{/code}
Nice and simple, all you have to do is remember the brackets!
{ 7 comments… read them below or add one }
Thanks…I was having the same problem.
Thanks, i was looking for this
thanks for sharing … saved time for me
Thank you also from me, I did appreciate the help!!
Thanks, It solves my problem.
This solved my problem.
Thanks.
Cool !!!! thanks a million.. solution was so darn simple :).
{ 1 trackback }