Hi All,
I am trying to write a query to pull out the next order but it isn't working if the next order is equal to the order that I am omitting. It works when the next order is different but when pulling the next order that is equal to 'Glucose' with a entered_date of ''2012-12-11 06:33:27.108', it is not displaying.
Thanks for any help!
Code:
SELECT
t.name, MAX(date)
FROM
(SELECT TOP 1
o.name, MAX(o.entered_date) as date
FROM
dbo.orders o
WHERE
o.clientid= 296400200
AND o.name <> 'GLUCOSE'
AND o.entered_date <> '2012-12-11 06:35:55.120'
GROUP BY o.name
ORDER BY date desc) t
GROUP BY t.name