Sample Header Ad - 728x90

Oracle optional select value

2 votes
1 answer
111 views
I'm writing query to select students with their Program, Country and Teacher. So far, I have the following query: SELECT H.STUDENT_CODE, H.FIRSTNAME, H.LASTNAME, H.PROGRAM, H.TEACHER_CODE, H.COUNTRY_CODE, AC.COUNTRY_NAME, P.PROGRAM_NAME, T.TEACHER_NAME FROM HTUD H, PROGRAM P, TEACHER T, AP_COUNTRY AC WHERE H.FIRSTNAME LIKE '%ark%' AND H.PROGRAM = P.PROGRAM AND H.TEACHER_CODE = T.TEACHER_CODE AND H.COUNTRY_CODE = AC.COUNTRY_CODE ORDER BY H.STUDENT_CODE ASC These two columns H.TEACHER_CODE and H.COUNTRY_CODE have some empty values. If I run the query above, it returns only students that have data in these two columns H.TEACHER_CODE and H.COUNTRY_CODE. However, I want to select all students wether they have data in these two columns or not. If they have data in H.TEACHER_CODE and H.COUNTRY_CODE column, then return Teacher and Country also, if they don't have, just return students without Teacher or Country. So, how do I select all students with or without Teacher or Country?
Asked by Narazana (123 rep)
May 12, 2014, 03:47 AM
Last activity: May 12, 2014, 04:46 AM