sql - multiple non ansi join -
i asked use non ansi join given query: q) display records above tables following fields – employeeid, employee name, department id, department name, start_date of job, end date of job, job title, country name, region name, difference in maximum salary , employee’s salary
tables given standard in "hr" connection tables in oracle 11g
i used following query:
select e.employee_id, first_name, e.deparment_id, department_name, start_date, end_date, job_title, country_name, region_name, (select max(salary) employees)-salary employees e, countries c, departments d, job_history jh, jobs j, locations l, regions r e.deparment_id = d.department_id , jh.employee_id = e.employee_id , e.job_id = j.job_id , d.location_id = l.location_id , l.country_id = c.country_id , c.region_id = r.region_id; the output getting redundant on entries. need resolving redundancy.
my output
101 neena 90 executive 28-10-93 15-03-97 president unites states of america americas 7000 101 neena 90 executive 21-09-89 27-10-93 president unites states of america americas 7000 102 lex 90 executive 13-01-93 24-07-98 administration vice president unites states of america americas 7000 200 jennifer 10 administration 01-07-94 31-12-98 administration assistant unites states of america americas 19600 200 jennifer 10 administration 17-09-87 17-06-93 administration assistant unites states of america americas 19600 176 jonathon 80 sales 01-01-99 31-12-99 sales representative united kingdom americas 15400 176 jonathon 80 sales 24-03-98 31-12-98 sales representative united kingdom americas 15400 201 michael 20 marketing 17-02-96 19-12-99 marketing manager canada americas 11000 desired output there wouldn't redundant data can see 'neena' or 'jonathon' repeating.
so have cross join: join conditions don't identify unique keys each table, 1 or more tables multiple records causing repetition of "unique" attributes.
without source data it;s hard sure, i'd guess it's job_history table: start_date , end_date values unique in each row. easiest way fix additional join on job_id:
and e.job_id = jh.job_id adding condition should cause job_history rows return latest role employee.
Comments
Post a Comment