I'm working on gathering information from my server but the query I've written doesn't return all the values I'm looking for. How would I go about using different types of nested joins or queries to get all the data I'm looking for?
The following snippet returns the total list of employee numbers I'm looking for:
select papf.employee_number, papf.full_name, paaf.person_id
from per_all_people_f papf, per_all_assignments_F paaf
where sysdate between papf.effective_start_date and papf.effective_end_date
and sysdate between paaf.effective_start_date and paaf.effective_end_date
and paaf.person_id > '0'
and papf.employee_number > '0'
and papf.person_id = paaf.person_id
order by 1;
Unfortunately this next snippet, while returning all the columns I want, doesn't return all the rows which I previously was getting from the above query:
select distinct loc.TOWN_OR_CITY city
,COALESCE(CASE WHEN (loc.location_code = 'Foo-Bar') THEN 'Foo-Bar' END, SUBSTR(loc.LOCATION_CODE, 1, INSTR(loc.LOCATION_CODE,'-','1','1')-1), loc.LOCATION_CODE) company
,loc.country
,papf.start_date created
,TRIM(SUBSTR(hou.name, INSTR(hou.name, '-','1','1')+1)) Department
,SUBSTR(pap.name, 1, INSTR(pap.name,'-','1','1')-1) Description
,CONCAT(COALESCE(papf.known_as, papf.first_name), concat(' ', papf.last_name)) DisplayName
,hou.attribute5 Division
,papf.employee_number EmployeeNumber
,papf.first_name givenname
,papf2.full_name Manager
,CONCAT(COALESCE(papf.known_as, papf.first_name), concat(' ', papf.last_name)) name
,pp.phone_number OfficePhone
,papf.known_as OtherName
,loc.region_2 state
,loc.postal_code postalcode
,papf.last_name Surname
,pp.phone_number Telephone#
from per_all_people_f papf
,per_all_positions pap
,per_phones pp
,per_all_people_f papf2
,per_all_assignments_f paaf
,hr_organization_units hou
,hr_locations_all loc
where
papf.person_id = paaf.person_id
and papf2.person_id = paaf.supervisor_id
and paaf.organization_id = hou.organization_id
and loc.location_id = paaf.location_id
and sysdate between papf.effective_start_date and papf.effective_end_date
and sysdate between paaf.effective_start_date and paaf.effective_end_date
and sysdate between papf2.effective_start_date and papf2.effective_end_date
and pp.parent_id = papf.person_id
and phone_type = 'Work Phone'
and paaf.position_id = pap.position_id
;
From all the posts I've read, I'm under the impression that the work I need to do is in the FROM clause but none of the attempts I've made so far have panned out.
I would greatly appreciate any information you can provide on how it's possible to get a new 'table' from a join (such as the working example in my first query), then only reference that table for the remaining attributes. The first query returns over 5,000 results while my seconds only returns 2,500. I need all the columns from the second query without sacrificing any rows which are returned from the first query. I don't mind if there are null values for some columns.
Aucun commentaire:
Enregistrer un commentaire