Reputation: 25
I might have a problem with my SQL query. In this query I'm combining 4 different tables.
courses
where general information is stored (course_number
, course_title
). employees
where general information of employees isstored (empname
, and a job_id
).job_course
(with the job_id
and the course_id
).emp_courses
(with the e_id
and the course_id
) Now I want to search a certain course - when the user presses the search button he should get two different results.
Here it is:
OpenDb_Open("select course_number,course_title, empname from course
INNER JOIN (job_course INNER JOIN (employee INNER JOIN emp_course
ON emp_course.e_id<>employee.e_id) ON job_course.job_id=employee.job_id)
ON course.course_id=job_course.course_id
where course_number like '" + coursenumber + "'");
Can someone please help me with this?
Upvotes: 1
Views: 187
Reputation: 67898
Courses the employee hasn't taken.
SELECT * FROM courses
WHERE course_number IN (
SELECT course_id FROM job_course
WHERE course_id NOT IN (
SELECT course_id FROM emp_courses
WHERE emp_id = {someid}
) AND job_id = (
SELECT job_id FROM employees
WHERE emp_id = {user_input}
)
)
Which employees still need to take a course.
SELECT emp_name FROM employees
WHERE emp_id NOT IN (
SELECT emp_id FROM emp_courses
WHERE course_id = {user_input}
)
Variant of above.
SELECT emp_name FROM employees
WHERE emp_id NOT IN (
SELECT emp_id FROM emp_courses
WHERE course_id = (
SELECT course_id FROM courses
WHERE course_number = {user_input}
)
)
Upvotes: 1