import java.sql.*; public class Q10 { public static void main( String [] args ) { String url = "jdbc:postgresql://localhost:5433/testdb"; String user = "test"; String password = "pqntslc"; try { /* QUERY * select distinct fullname * from ( (enrollments en * left join students st) * on en.student_iid = st.student_iid) as en_st * left join courses co * on en_st.course_iid = co.course_iid) as en_st_co * where en_st_co.code = 'a1010'; * */ Connection connection = DriverManager.getConnection(url, user,password); Statement st = connection.createStatement(); String query = "SELECT DISTINCT fullname " + "FROM ((enrollments en " + "LEFT JOIN students st " + "ON en.student_iid = st.student_iid) AS en_st " + "LEFT JOIN courses co " + "ON en_st.course_iid = co.course_iid) AS en_st_co " + "WHERE en_st_co.code = 'a1010';"; ResultSet rs = st.executeQuery(query); System.out.println("Imprimiendo la lista de los alumnos del curso con codigo \'a1010\' "); while(rs.next() ) { String fullname = rs.getString("fullname"); System.out.println(fullname); } }catch(SQLException e) { e.printStackTrace();; } } }