Hi there
I am new to SQL. I am making a simple employee phonebook with tables employee, job, and department. (Employee is recursive in that it also stores the managers info.)
My statement works as long as mgr_id is not null (employee table). When it is null an empty result set is returned - but I know there is an employee beginning with C in that table.
My statement:
SELECT e.employee_id, e.surname, e.firstname, e.phonenum, d.dept_id, d.deptname, j.job_id, j.jobname, e.mgr_id, e1.surname AS mgrsurname, e1.firstname AS mgrfirstname
FROM employee AS e, employee AS e1, department AS d, job AS j
WHERE e.surname LIKE 'C%'
AND e.dept_id = d.dept_id
AND e.job_id = j.job_id
AND e.mgr_id = e1.employee_id;
//problem with query - no results when mgr is null.
//example results (WHERE e.surname LIKE 'p%')
Emp Id Surname First name Phone Dept Job Mgr
6 Patrick Tara 5551232 Graphics Senior Graphics Artist John Keogh
Can someone help me?
When I set the sql statement to allow a null for mgr_id I am getting a cartesian result instead of one line. I.e I get 7 results with the same name (as there are 7 entries in the dbase)
I am new to SQL. I am making a simple employee phonebook with tables employee, job, and department. (Employee is recursive in that it also stores the managers info.)
My statement works as long as mgr_id is not null (employee table). When it is null an empty result set is returned - but I know there is an employee beginning with C in that table.
My statement:
SELECT e.employee_id, e.surname, e.firstname, e.phonenum, d.dept_id, d.deptname, j.job_id, j.jobname, e.mgr_id, e1.surname AS mgrsurname, e1.firstname AS mgrfirstname
FROM employee AS e, employee AS e1, department AS d, job AS j
WHERE e.surname LIKE 'C%'
AND e.dept_id = d.dept_id
AND e.job_id = j.job_id
AND e.mgr_id = e1.employee_id;
//problem with query - no results when mgr is null.
//example results (WHERE e.surname LIKE 'p%')
Emp Id Surname First name Phone Dept Job Mgr
6 Patrick Tara 5551232 Graphics Senior Graphics Artist John Keogh
Can someone help me?
When I set the sql statement to allow a null for mgr_id I am getting a cartesian result instead of one line. I.e I get 7 results with the same name (as there are 7 entries in the dbase)