Web Listing 1: Roy’s Solution WITH Eight(i) AS (SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8) SELECT A.i as a, B.i as b, C.i as c, D.i as d, E.i as e, F.i as f, g.i as g, H.i as h FROM Eight as A JOIN Eight as B ON B.i <> A.i and (B.i - A.i) NOT IN (-1, +1) JOIN Eight as C ON C.i NOT IN (A.i, B.i) AND (C.i - A.i) NOT IN (-2, +2) AND (C.i - B.i) NOT IN (-1, +1) JOIN Eight as D ON D.i NOT IN (A.i, B.i, C.i) AND (D.i - A.i) NOT IN (-3, +3) AND (D.i - B.i) NOT IN (-2, +2) AND (D.i - C.i) NOT IN (-1, +1) JOIN Eight as E ON E.i NOT IN (A.i, B.i, C.i, D.i) AND (E.i - A.i) NOT IN (-4, +4) AND (E.i - B.i) NOT IN (-3, +3) AND (E.i - C.i) NOT IN (-2, +2) AND (E.i - D.i) NOT IN (-1, +1) JOIN Eight as F ON F.i NOT IN (A.i, B.i, C.i, D.i, E.i) AND (F.i - A.i) NOT IN (-5, +5) AND (F.i - B.i) NOT IN (-4, +4) AND (F.i - C.i) NOT IN (-3, +3) AND (F.i - D.i) NOT IN (-2, +2) AND (F.i - E.i) NOT IN (-1, +1) JOIN Eight as G ON G.i NOT IN (A.i, B.i, C.i, D.i, E.i, F.i) AND (G.i - A.i) NOT IN (-6, +6) AND (G.i - B.i) NOT IN (-5, +5) AND (G.i - C.i) NOT IN (-4, +4) AND (G.i - D.i) NOT IN (-3, +3) AND (G.i - E.i) NOT IN (-2, +2) AND (G.i - F.i) NOT IN (-1, +1) JOIN Eight as H ON H.i NOT IN (A.i, B.i, C.i, D.i, E.i, F.i, G.i) AND (H.i - A.i) NOT IN (-7, +7) AND (H.i - B.i) NOT IN (-6, +6) AND (H.i - C.i) NOT IN (-5, +5) AND (H.i - D.i) NOT IN (-4, +4) AND (H.i - E.i) NOT IN (-3, +3) AND (H.i - F.i) NOT IN (-2, +2) AND (H.i - G.i) NOT IN (-1, +1) ORDER BY a, b, c, d, e, f, g;