Subquery Order By Error
742468Dec 21 2009 — edited Dec 23 2009Here is the query I am wanting to use:
SELECT * FROM (SELECT * FROM WO WHERE (WO.ORIGINATOR = '22214' OR WO.ASSIGNEDTO = '22214' OR WO.ASSIGNEDBY = '22214' AND TO_CHAR(CLOSEDATE, 'YYYY/MM/DD') = '1900/01/01') ORDER BY WONUM) WHERE ROWNUM <= 50
When I try and use it is get this error:
[Microsoft][ODBC driver for Oracle][Oracle]ORA-00907: missing right parenthesis
To me the query looks fine and I determined the problem was with the order by because in my subquery if I run this query:
SELECT * FROM (SELECT * FROM WO WHERE (WO.ORIGINATOR = '22214' OR WO.ASSIGNEDTO = '22214' OR WO.ASSIGNEDBY = '22214' AND TO_CHAR(CLOSEDATE, 'YYYY/MM/DD') = '1900/01/01')) WHERE ROWNUM <= 50
Everything works fine but my data in not in proper order. I am doing the order by in a subquery because if i just do a "and" then i just get the first 50 results of the table sorted and this is not what i want. I want the whole table sorted and then out of that sorted table pull the first 50 results.
Anyone have any ideas on why this is not working or what I can do?
I am wondering if it has something to do with my version but I do not know how to check version as I can only access database with PHP 5 and and odbc connect, also I am new to Oracle (I have about 3 days experience).