Celtic Coding Solutions Blog

Celtic Coding Solutions Blog - for everything computer related

Visual FoxPro SELECT UNION and ORDER BY

Found a lovely weirdy in Visual FoxPro 7 and using UNION and ORDER BY, try the following:-

SELECT Field1, Field2 FROM Table1;

UNION ALL ;

SELECT Field1, Field2 FROM Table2;

ORDER BY Field2;

INTO CURSOR Table3

This statement creates the error:-

SQL: ORDER BY clause is invalid.

This is perfectly good SQL syntax so why is FoxPro not allowing it? 

Well not sure why by a way around it is using the ORDER BY with abortion pill ny a field value so the code best pills would now be:-

SELECT Field1, Field2 FROM Table1;

UNION ALL ;

SELECT Field1, Field2 FROM Table2;

ORDER BY 2;

INTO CURSOR Table3

Comments are closed