
CREATE TABLE S (
   v smallint NOT NULL PRIMARY KEY
   );

INSERT INTO S (v) VALUES (1), (2), (3), (4), (5), (6);

SELECT  c11.v, c12.v, c13.v, c14.v, c15.v, c16.v,
        c21.v, c22.v, c23.v, c24.v, c25.v, c26.v,
        c31.v, c32.v, c33.v, c34.v, c35.v, c36.v,
        c41.v, c42.v, c43.v, c44.v, c45.v, c46.v,
        c51.v, c52.v, c53.v, c54.v, c55.v, c56.v,
        c61.v, c62.v, c63.v, c64.v, c65.v, c66.v
  FROM  S c11, S c12, S c13, S c14, S c15, S c16,
        S c21, S c22, S c23, S c24, S c25, S c26,
        S c31, S c32, S c33, S c34, S c35, S c36,
        S c41, S c42, S c43, S c44, S c45, S c46,
        S c51, S c52, S c53, S c54, S c55, S c56,
        S c61, S c62, S c63, S c64, S c65, S c66
 WHERE  true

        -- Row 1
   AND  c11.v != c12.v
   AND  c11.v != c13.v
   AND  c11.v != c14.v
   AND  c11.v != c15.v
   AND  c11.v != c16.v
   AND  c12.v != c13.v
   AND  c12.v != c14.v
   AND  c12.v != c15.v
   AND  c12.v != c16.v
   AND  c13.v != c14.v
   AND  c13.v != c15.v
   AND  c13.v != c16.v
   AND  c14.v != c15.v
   AND  c14.v != c16.v
   AND  c15.v != c16.v

        -- Row 2
   AND  c21.v != c22.v
   AND  c21.v != c23.v
   AND  c21.v != c24.v
   AND  c21.v != c25.v
   AND  c21.v != c26.v
   AND  c22.v != c23.v
   AND  c22.v != c24.v
   AND  c22.v != c25.v
   AND  c22.v != c26.v
   AND  c23.v != c24.v
   AND  c23.v != c25.v
   AND  c23.v != c26.v
   AND  c24.v != c25.v
   AND  c24.v != c26.v
   AND  c25.v != c26.v

        -- Row 3
   AND  c31.v != c32.v
   AND  c31.v != c33.v
   AND  c31.v != c34.v
   AND  c31.v != c35.v
   AND  c31.v != c36.v
   AND  c32.v != c33.v
   AND  c32.v != c34.v
   AND  c32.v != c35.v
   AND  c32.v != c36.v
   AND  c33.v != c34.v
   AND  c33.v != c35.v
   AND  c33.v != c36.v
   AND  c34.v != c35.v
   AND  c34.v != c36.v
   AND  c35.v != c36.v

        -- Row 4
   AND  c41.v != c42.v
   AND  c41.v != c43.v
   AND  c41.v != c44.v
   AND  c41.v != c45.v
   AND  c41.v != c46.v
   AND  c42.v != c43.v
   AND  c42.v != c44.v
   AND  c42.v != c45.v
   AND  c42.v != c46.v
   AND  c43.v != c44.v
   AND  c43.v != c45.v
   AND  c43.v != c46.v
   AND  c44.v != c45.v
   AND  c44.v != c46.v
   AND  c45.v != c46.v

        -- Row 5
   AND  c51.v != c52.v
   AND  c51.v != c53.v
   AND  c51.v != c54.v
   AND  c51.v != c55.v
   AND  c51.v != c56.v
   AND  c52.v != c53.v
   AND  c52.v != c54.v
   AND  c52.v != c55.v
   AND  c52.v != c56.v
   AND  c53.v != c54.v
   AND  c53.v != c55.v
   AND  c53.v != c56.v
   AND  c54.v != c55.v
   AND  c54.v != c56.v
   AND  c55.v != c56.v

        -- Row 6
   AND  c61.v != c62.v
   AND  c61.v != c63.v
   AND  c61.v != c64.v
   AND  c61.v != c65.v
   AND  c61.v != c66.v
   AND  c62.v != c63.v
   AND  c62.v != c64.v
   AND  c62.v != c65.v
   AND  c62.v != c66.v
   AND  c63.v != c64.v
   AND  c63.v != c65.v
   AND  c63.v != c66.v
   AND  c64.v != c65.v
   AND  c64.v != c66.v
   AND  c65.v != c66.v

        -- Col 1
   AND  c11.v != c21.v
   AND  c11.v != c31.v
   AND  c11.v != c41.v
   AND  c11.v != c51.v
   AND  c11.v != c61.v
   AND  c21.v != c31.v
   AND  c21.v != c41.v
   AND  c21.v != c51.v
   AND  c21.v != c61.v
   AND  c31.v != c41.v
   AND  c31.v != c51.v
   AND  c31.v != c61.v
   AND  c41.v != c51.v
   AND  c41.v != c61.v
   AND  c51.v != c61.v

        -- Col 2
   AND  c12.v != c22.v
   AND  c12.v != c32.v
   AND  c12.v != c42.v
   AND  c12.v != c52.v
   AND  c12.v != c62.v
   AND  c22.v != c32.v
   AND  c22.v != c42.v
   AND  c22.v != c52.v
   AND  c22.v != c62.v
   AND  c32.v != c42.v
   AND  c32.v != c52.v
   AND  c32.v != c62.v
   AND  c42.v != c52.v
   AND  c42.v != c62.v
   AND  c52.v != c62.v

        -- Col 3
   AND  c13.v != c23.v
   AND  c13.v != c33.v
   AND  c13.v != c43.v
   AND  c13.v != c53.v
   AND  c13.v != c63.v
   AND  c23.v != c33.v
   AND  c23.v != c43.v
   AND  c23.v != c53.v
   AND  c23.v != c63.v
   AND  c33.v != c43.v
   AND  c33.v != c53.v
   AND  c33.v != c63.v
   AND  c43.v != c53.v
   AND  c43.v != c63.v
   AND  c53.v != c63.v

        -- Col 4
   AND  c14.v != c24.v
   AND  c14.v != c34.v
   AND  c14.v != c44.v
   AND  c14.v != c54.v
   AND  c14.v != c64.v
   AND  c24.v != c34.v
   AND  c24.v != c44.v
   AND  c24.v != c54.v
   AND  c24.v != c64.v
   AND  c34.v != c44.v
   AND  c34.v != c54.v
   AND  c34.v != c64.v
   AND  c44.v != c54.v
   AND  c44.v != c64.v
   AND  c54.v != c64.v

        -- Col 5
   AND  c15.v != c25.v
   AND  c15.v != c35.v
   AND  c15.v != c45.v
   AND  c15.v != c55.v
   AND  c15.v != c65.v
   AND  c25.v != c35.v
   AND  c25.v != c45.v
   AND  c25.v != c55.v
   AND  c25.v != c65.v
   AND  c35.v != c45.v
   AND  c35.v != c55.v
   AND  c35.v != c65.v
   AND  c45.v != c55.v
   AND  c45.v != c65.v
   AND  c55.v != c65.v

        -- Col 6
   AND  c16.v != c26.v
   AND  c16.v != c36.v
   AND  c16.v != c46.v
   AND  c16.v != c56.v
   AND  c16.v != c66.v
   AND  c26.v != c36.v
   AND  c26.v != c46.v
   AND  c26.v != c56.v
   AND  c26.v != c66.v
   AND  c36.v != c46.v
   AND  c36.v != c56.v
   AND  c36.v != c66.v
   AND  c46.v != c56.v
   AND  c46.v != c66.v
   AND  c56.v != c66.v

        -- Block (1, 1)
   AND  c11.v != c22.v
   AND  c11.v != c23.v
   AND  c12.v != c21.v
   AND  c12.v != c23.v
   AND  c13.v != c21.v
   AND  c13.v != c22.v

        -- Block (1, 4)
   AND  c14.v != c25.v
   AND  c14.v != c26.v
   AND  c15.v != c24.v
   AND  c15.v != c26.v
   AND  c16.v != c24.v
   AND  c16.v != c25.v

        -- Block (3, 1)
   AND  c31.v != c42.v
   AND  c31.v != c43.v
   AND  c32.v != c41.v
   AND  c32.v != c43.v
   AND  c33.v != c41.v
   AND  c33.v != c42.v

        -- Block (3, 4)
   AND  c34.v != c45.v
   AND  c34.v != c46.v
   AND  c35.v != c44.v
   AND  c35.v != c46.v
   AND  c36.v != c44.v
   AND  c36.v != c45.v

        -- Block (5, 1)
   AND  c51.v != c62.v
   AND  c51.v != c63.v
   AND  c52.v != c61.v
   AND  c52.v != c63.v
   AND  c53.v != c61.v
   AND  c53.v != c62.v

        -- Block (5, 4)
   AND  c54.v != c65.v
   AND  c54.v != c66.v
   AND  c55.v != c64.v
   AND  c55.v != c66.v
   AND  c56.v != c64.v
   AND  c56.v != c65.v

        -- Clues
   AND  c11.v = 3
   AND  c16.v = 4
   AND  c23.v = 4
   AND  c24.v = 3
   AND  c32.v = 3
   AND  c35.v = 6
   AND  c42.v = 4
   AND  c45.v = 1
   AND  c53.v = 2
   AND  c54.v = 1
   AND  c61.v = 1
   AND  c66.v = 2

;
