I have the following query with a sub query that I am trying to make work. my first attempt at using a sub-query in a where statement. can anybody tell me why this does not work? I get an error that basically keywork ORDER not expected. Valid tokens: Union Except. (#-199)
SELECT DITRLR,COUNT(ORODR#) AS OCOUNT,SUM(CAST(ORESTR AS DOUBLE)) AS REV
INNER JOIN LOAD ON DIODR# = ORODR#
WHERE DITRLR IN
(SELECT DITRLR FROM ORDER INNER JOIN LOAD ON ORODR# = DIODR# WHERE ORPDAT BETWEEN 2007001 AND 2007365 AND DIDISP = '01'
AND ORCUST IN('AWISH','PASPRO','SAPAPO') GROUP BY DITRLR ORDER BY COUNT(ORODR#) DESC FETCH FIRST 10 ROW ONLY)
AND ORPDAT BETWEEN 207001 AND 2007365 AND DIDISP = '01'
GROUP BY DITRLR