What is wrong with my query? - by user299874 SELECT h11, HA11 FROM florin.h11 WHERE (3>d1 AND 3<d2) OR (3>d1 AND 3=d2 AND id=MAX(id)) UNION (3=d1 AND 3<d2 AND id=MIN(id));` Here a screenshot of my table stucture: Read the article