SELECT DISTINCT * FROM tbl1 INNER JOIN tbl2 ON id1 = id2 WHERE 1=1 LEFT OUTER JOIN l3;