create table points (line number, point number); insert into points (line, point) values (0, 0); insert into points (line, point) values (0, 1); insert into points (line, point) values (1, 0); insert into points (line, point) values (1, 2); insert into points (line, point) values (1, 4); insert into points (line, point) values (1, 6); insert into points (line, point) values (2, 0); insert into points (line, point) values (2, 3); insert into points (line, point) values (2, 7); insert into points (line, point) values (2, 9); insert into points (line, point) values (3, 0); insert into points (line, point) values (3, 5); insert into points (line, point) values (3, 8); insert into points (line, point) values (3, 10); insert into points (line, point) values (4, 1); insert into points (line, point) values (4, 2); insert into points (line, point) values (4, 3); insert into points (line, point) values (4, 5); insert into points (line, point) values (5, 1); insert into points (line, point) values (5, 4); insert into points (line, point) values (5, 7); insert into points (line, point) values (5, 8); insert into points (line, point) values (6, 1); insert into points (line, point) values (6, 6); insert into points (line, point) values (6, 9); insert into points (line, point) values (6, 10); commit; select distinct a.point, b.point, c.point from points a, points b, points c where exists (select 'ab_colinear' from points a1, points b1 where a1.line = b1.line and a1.point = a.point and b1.point = b.point) and exists (select 'bc_colinear' from points b1, points c1 where c1.line = b1.line and c1.point = c.point and b1.point = b.point) and exists (select 'ac_colinear' from points a1, points c1 where a1.line = c1.line and a1.point = a.point and c1.point = c.point) and not exists (select 'abc_colinear' from points a1, points b1, points c1 where a1.line = b1.line and b1.line = c1.line and a1.point = a.point and b1.point = b.point and c1.point = c.point) and a.point < b.point and b.point < c.point ;