DROP TABLE IF EXISTS ranges;
CREATE TABLE ranges (
id INT PRIMARY KEY,
start YEAR,
end YEAR,
UNIQUE KEY range_key(start, end)
);
INSERT INTO ranges VALUES (1, 2012, 2155);
INSERT INTO ranges VALUES (2, 1901, 2012);
INSERT INTO ranges VALUES (3, 2155, 1901);
INSERT INTO ranges VALUES (4, 1901, 2155);
SELECT * FROM ranges FORCE INDEX(range_key)
ORDER BY start, end;
id	start	end
2	1901	2012
4	1901	2155
1	2012	2155
3	2155	1901
DROP TABLE ranges;
