String select = "select distinct s.ID,s.EXAM_NUM,s.NAME,s.ID_NUM "; String sql = " from STUDENT s " + "left join (select distinct CODE,NAME from COLLEGE) b on s.COLLEGE_CODE = b.CODE " + "left join (select distinct CODE,NAME,XZ from MAJOR) c on s.MAJOR_CODE = c.CODE " + "left join (select distinct CODE,NAME from CLASSES) d on s.CLASSES_CODE = d.CODE " + "where s.EXAM_NUM in (select EXAM_CODE FROM PAYMENT_STUDENT where YEAR = ?) "; List