The error message says it all, but its meaning is easier to understand if you see it.
Using an aggregate function in your select list (i.e. MAX(OE.NextContactDate)
), aggregate functions need to contain all entries in your select list...
SELECT
MAX(o.ordernum), -- technically contained in an aggregate function - setting aside that it's probably not what you want otherwise
MAX(o.SCHEDATTEMPT), -- same
MAX(o.lastcontactdate), -- same
MAX(OE.NextContactDate) AS NextContactDate
FROM orderevents OE
FULL outer join orde_ o
ON o.ORDERID=oe.OrderId
WHERE O.lastcontactdate is not null and SCHEDULED is null and DROPTIME is null
ORDER by MAX(o.lastcontactdate)
...or entries in your select list that are not contained by aggregate functions need to be in a GROUP BY
clause:
SELECT
o.ordernum,
o.SCHEDATTEMPT,
o.lastcontactdate,
MAX(OE.NextContactDate) AS NextContactDate
FROM orderevents OE
FULL outer join orde_ o
ON o.ORDERID=oe.OrderId
WHERE O.lastcontactdate is not null and SCHEDULED is null and DROPTIME is null
GROUP BY o.ordernum, o.SCHEDATTEMPT, o.lastcontactdate -- added GROUP BY clause
ORDER by o.lastcontactdate
I suspect you really want the second fix - to add a GROUP BY
clause to your query.