Multiple rows in spite of using outer join












0















I have 2 tables below



Paam Table
AssignmentID PersonID AssignmentType
300000014199240 300000014199145 E
300000014199174 300000014199145 ET

Par Table
ASGResponsID AssignmentID PersonID Responsibility_Type
300000015244074 300000014199240 300000014199145 RC_HR_BP
300000015242351 300000014199240 300000014199145 RC_HR_BP
300000015244070 300000014199240 300000014199145 RC_HR_BP


I want to join these 2 tables and get output like below



PersonID         Responsiblity_Type
300000014199145 RC_HR_BP


I am using the below query



select 
par.PersonID, par.Responsibility_Type
from
per_all_assignments_m paam, per_asg_responsibilities par
where
sysdate between nvl(paam.effective_start_date,sysdate) and
nvl(paam.effective_end_date,sysdate)
and paam.assignment_type='E'
and paam.assignment_id = par.assignment_id(+)
and paam.person_id = '300000014199145';


Instead I am getting output like below



PersonID         Responsiblity_Type
300000014199145 RC_HR_BP
300000014199145 RC_HR_BP
300000014199145 RC_HR_BP


In spite of using left outer join I am getting multiple rows, why is this happening?



Can someone please help me understand ?



Thanks,
Shivam










share|improve this question


















  • 1





    Wow, it's been some time I've last seen this ancient outer join syntax. Which Oracle version are you using?

    – Thorsten Kettner
    Jan 3 at 17:03











  • I am using Oracle 11

    – shivam
    Jan 3 at 17:09











  • And the task is exactly what? Show all different responsibility types for person '300000014199145' assignments of type 'E'?

    – Thorsten Kettner
    Jan 3 at 17:09






  • 1





    @shivam: Then use proper ANSI joins (from a left outer join b on ...). The join syntax you are using was made redundant with the standard SQL joins.

    – Thorsten Kettner
    Jan 3 at 17:11











  • I just want to show in output the personId and responsibility_type, since this specific person has single responsibility_type then only 1 row should come in output.

    – shivam
    Jan 3 at 17:13
















0















I have 2 tables below



Paam Table
AssignmentID PersonID AssignmentType
300000014199240 300000014199145 E
300000014199174 300000014199145 ET

Par Table
ASGResponsID AssignmentID PersonID Responsibility_Type
300000015244074 300000014199240 300000014199145 RC_HR_BP
300000015242351 300000014199240 300000014199145 RC_HR_BP
300000015244070 300000014199240 300000014199145 RC_HR_BP


I want to join these 2 tables and get output like below



PersonID         Responsiblity_Type
300000014199145 RC_HR_BP


I am using the below query



select 
par.PersonID, par.Responsibility_Type
from
per_all_assignments_m paam, per_asg_responsibilities par
where
sysdate between nvl(paam.effective_start_date,sysdate) and
nvl(paam.effective_end_date,sysdate)
and paam.assignment_type='E'
and paam.assignment_id = par.assignment_id(+)
and paam.person_id = '300000014199145';


Instead I am getting output like below



PersonID         Responsiblity_Type
300000014199145 RC_HR_BP
300000014199145 RC_HR_BP
300000014199145 RC_HR_BP


In spite of using left outer join I am getting multiple rows, why is this happening?



Can someone please help me understand ?



Thanks,
Shivam










share|improve this question


















  • 1





    Wow, it's been some time I've last seen this ancient outer join syntax. Which Oracle version are you using?

    – Thorsten Kettner
    Jan 3 at 17:03











  • I am using Oracle 11

    – shivam
    Jan 3 at 17:09











  • And the task is exactly what? Show all different responsibility types for person '300000014199145' assignments of type 'E'?

    – Thorsten Kettner
    Jan 3 at 17:09






  • 1





    @shivam: Then use proper ANSI joins (from a left outer join b on ...). The join syntax you are using was made redundant with the standard SQL joins.

    – Thorsten Kettner
    Jan 3 at 17:11











  • I just want to show in output the personId and responsibility_type, since this specific person has single responsibility_type then only 1 row should come in output.

    – shivam
    Jan 3 at 17:13














0












0








0








I have 2 tables below



Paam Table
AssignmentID PersonID AssignmentType
300000014199240 300000014199145 E
300000014199174 300000014199145 ET

Par Table
ASGResponsID AssignmentID PersonID Responsibility_Type
300000015244074 300000014199240 300000014199145 RC_HR_BP
300000015242351 300000014199240 300000014199145 RC_HR_BP
300000015244070 300000014199240 300000014199145 RC_HR_BP


I want to join these 2 tables and get output like below



PersonID         Responsiblity_Type
300000014199145 RC_HR_BP


I am using the below query



select 
par.PersonID, par.Responsibility_Type
from
per_all_assignments_m paam, per_asg_responsibilities par
where
sysdate between nvl(paam.effective_start_date,sysdate) and
nvl(paam.effective_end_date,sysdate)
and paam.assignment_type='E'
and paam.assignment_id = par.assignment_id(+)
and paam.person_id = '300000014199145';


Instead I am getting output like below



PersonID         Responsiblity_Type
300000014199145 RC_HR_BP
300000014199145 RC_HR_BP
300000014199145 RC_HR_BP


In spite of using left outer join I am getting multiple rows, why is this happening?



Can someone please help me understand ?



Thanks,
Shivam










share|improve this question














I have 2 tables below



Paam Table
AssignmentID PersonID AssignmentType
300000014199240 300000014199145 E
300000014199174 300000014199145 ET

Par Table
ASGResponsID AssignmentID PersonID Responsibility_Type
300000015244074 300000014199240 300000014199145 RC_HR_BP
300000015242351 300000014199240 300000014199145 RC_HR_BP
300000015244070 300000014199240 300000014199145 RC_HR_BP


I want to join these 2 tables and get output like below



PersonID         Responsiblity_Type
300000014199145 RC_HR_BP


I am using the below query



select 
par.PersonID, par.Responsibility_Type
from
per_all_assignments_m paam, per_asg_responsibilities par
where
sysdate between nvl(paam.effective_start_date,sysdate) and
nvl(paam.effective_end_date,sysdate)
and paam.assignment_type='E'
and paam.assignment_id = par.assignment_id(+)
and paam.person_id = '300000014199145';


Instead I am getting output like below



PersonID         Responsiblity_Type
300000014199145 RC_HR_BP
300000014199145 RC_HR_BP
300000014199145 RC_HR_BP


In spite of using left outer join I am getting multiple rows, why is this happening?



Can someone please help me understand ?



Thanks,
Shivam







sql oracle outer-join multiple-records






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 16:48









shivamshivam

132519




132519








  • 1





    Wow, it's been some time I've last seen this ancient outer join syntax. Which Oracle version are you using?

    – Thorsten Kettner
    Jan 3 at 17:03











  • I am using Oracle 11

    – shivam
    Jan 3 at 17:09











  • And the task is exactly what? Show all different responsibility types for person '300000014199145' assignments of type 'E'?

    – Thorsten Kettner
    Jan 3 at 17:09






  • 1





    @shivam: Then use proper ANSI joins (from a left outer join b on ...). The join syntax you are using was made redundant with the standard SQL joins.

    – Thorsten Kettner
    Jan 3 at 17:11











  • I just want to show in output the personId and responsibility_type, since this specific person has single responsibility_type then only 1 row should come in output.

    – shivam
    Jan 3 at 17:13














  • 1





    Wow, it's been some time I've last seen this ancient outer join syntax. Which Oracle version are you using?

    – Thorsten Kettner
    Jan 3 at 17:03











  • I am using Oracle 11

    – shivam
    Jan 3 at 17:09











  • And the task is exactly what? Show all different responsibility types for person '300000014199145' assignments of type 'E'?

    – Thorsten Kettner
    Jan 3 at 17:09






  • 1





    @shivam: Then use proper ANSI joins (from a left outer join b on ...). The join syntax you are using was made redundant with the standard SQL joins.

    – Thorsten Kettner
    Jan 3 at 17:11











  • I just want to show in output the personId and responsibility_type, since this specific person has single responsibility_type then only 1 row should come in output.

    – shivam
    Jan 3 at 17:13








1




1





Wow, it's been some time I've last seen this ancient outer join syntax. Which Oracle version are you using?

– Thorsten Kettner
Jan 3 at 17:03





Wow, it's been some time I've last seen this ancient outer join syntax. Which Oracle version are you using?

– Thorsten Kettner
Jan 3 at 17:03













I am using Oracle 11

– shivam
Jan 3 at 17:09





I am using Oracle 11

– shivam
Jan 3 at 17:09













And the task is exactly what? Show all different responsibility types for person '300000014199145' assignments of type 'E'?

– Thorsten Kettner
Jan 3 at 17:09





And the task is exactly what? Show all different responsibility types for person '300000014199145' assignments of type 'E'?

– Thorsten Kettner
Jan 3 at 17:09




1




1





@shivam: Then use proper ANSI joins (from a left outer join b on ...). The join syntax you are using was made redundant with the standard SQL joins.

– Thorsten Kettner
Jan 3 at 17:11





@shivam: Then use proper ANSI joins (from a left outer join b on ...). The join syntax you are using was made redundant with the standard SQL joins.

– Thorsten Kettner
Jan 3 at 17:11













I just want to show in output the personId and responsibility_type, since this specific person has single responsibility_type then only 1 row should come in output.

– shivam
Jan 3 at 17:13





I just want to show in output the personId and responsibility_type, since this specific person has single responsibility_type then only 1 row should come in output.

– shivam
Jan 3 at 17:13












2 Answers
2






active

oldest

votes


















0














Start by using a regular join with proper syntax:



select par.PersonID, par.Responsibility_Type 
from per_all_assignments_m paam join
per_asg_responsibilities par
on paam.assignment_id = par.assignment_id and
paam.person_id = par.person_id -- presumably also needed for the join
where sysdate between nvl(paam.effective_start_date, sysdate) and
nvl(paam.effective_end_date, sysdate) and
paam.assignment_type = 'E' and
paam.person_id = '300000014199145';


Your intention with the outer join might be:



select par.PersonID, par.Responsibility_Type 
from per_asg_responsibilities par left join
per_all_assignments_m paam
on paam.assignment_id = par.assignment_id and
paam.person_id = par.person_id and
sysdate between nvl(paam.effective_start_date, sysdate) and
nvl(paam.effective_end_date, sysdate) and
paam.assignment_type = 'E' and
where par.person_id = '300000014199145';





share|improve this answer
























  • Hi, Thanks for the reply. I have already tried these but still getting same multiple rows. I think I may need to use row_num function

    – shivam
    Jan 3 at 17:10



















0














Based on your data, you're getting the correct results. All three rows in the par table have the same assignmentId (300000014199240) so will be returned by your query regardless of the join syntax.



Adding a "Distinct" clause will get you the results you want.



select DISTINCT
par.PersonID, par.Responsibility_Type
from
per_all_assignments_m paam, per_asg_responsibilities par
where
sysdate between nvl(paam.effective_start_date,sysdate) and
nvl(paam.effective_end_date,sysdate)
and paam.assignment_type='E'
and paam.assignment_id = par.assignment_id(+)
and paam.person_id = '300000014199145';


I set this up in a SQL Fiddle here http://sqlfiddle.com/#!4/d7b7f/8. Note: I removed the date field references since you didn't give us data for those, but it shouldn't affect the results based on how you described the problem.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026491%2fmultiple-rows-in-spite-of-using-outer-join%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Start by using a regular join with proper syntax:



    select par.PersonID, par.Responsibility_Type 
    from per_all_assignments_m paam join
    per_asg_responsibilities par
    on paam.assignment_id = par.assignment_id and
    paam.person_id = par.person_id -- presumably also needed for the join
    where sysdate between nvl(paam.effective_start_date, sysdate) and
    nvl(paam.effective_end_date, sysdate) and
    paam.assignment_type = 'E' and
    paam.person_id = '300000014199145';


    Your intention with the outer join might be:



    select par.PersonID, par.Responsibility_Type 
    from per_asg_responsibilities par left join
    per_all_assignments_m paam
    on paam.assignment_id = par.assignment_id and
    paam.person_id = par.person_id and
    sysdate between nvl(paam.effective_start_date, sysdate) and
    nvl(paam.effective_end_date, sysdate) and
    paam.assignment_type = 'E' and
    where par.person_id = '300000014199145';





    share|improve this answer
























    • Hi, Thanks for the reply. I have already tried these but still getting same multiple rows. I think I may need to use row_num function

      – shivam
      Jan 3 at 17:10
















    0














    Start by using a regular join with proper syntax:



    select par.PersonID, par.Responsibility_Type 
    from per_all_assignments_m paam join
    per_asg_responsibilities par
    on paam.assignment_id = par.assignment_id and
    paam.person_id = par.person_id -- presumably also needed for the join
    where sysdate between nvl(paam.effective_start_date, sysdate) and
    nvl(paam.effective_end_date, sysdate) and
    paam.assignment_type = 'E' and
    paam.person_id = '300000014199145';


    Your intention with the outer join might be:



    select par.PersonID, par.Responsibility_Type 
    from per_asg_responsibilities par left join
    per_all_assignments_m paam
    on paam.assignment_id = par.assignment_id and
    paam.person_id = par.person_id and
    sysdate between nvl(paam.effective_start_date, sysdate) and
    nvl(paam.effective_end_date, sysdate) and
    paam.assignment_type = 'E' and
    where par.person_id = '300000014199145';





    share|improve this answer
























    • Hi, Thanks for the reply. I have already tried these but still getting same multiple rows. I think I may need to use row_num function

      – shivam
      Jan 3 at 17:10














    0












    0








    0







    Start by using a regular join with proper syntax:



    select par.PersonID, par.Responsibility_Type 
    from per_all_assignments_m paam join
    per_asg_responsibilities par
    on paam.assignment_id = par.assignment_id and
    paam.person_id = par.person_id -- presumably also needed for the join
    where sysdate between nvl(paam.effective_start_date, sysdate) and
    nvl(paam.effective_end_date, sysdate) and
    paam.assignment_type = 'E' and
    paam.person_id = '300000014199145';


    Your intention with the outer join might be:



    select par.PersonID, par.Responsibility_Type 
    from per_asg_responsibilities par left join
    per_all_assignments_m paam
    on paam.assignment_id = par.assignment_id and
    paam.person_id = par.person_id and
    sysdate between nvl(paam.effective_start_date, sysdate) and
    nvl(paam.effective_end_date, sysdate) and
    paam.assignment_type = 'E' and
    where par.person_id = '300000014199145';





    share|improve this answer













    Start by using a regular join with proper syntax:



    select par.PersonID, par.Responsibility_Type 
    from per_all_assignments_m paam join
    per_asg_responsibilities par
    on paam.assignment_id = par.assignment_id and
    paam.person_id = par.person_id -- presumably also needed for the join
    where sysdate between nvl(paam.effective_start_date, sysdate) and
    nvl(paam.effective_end_date, sysdate) and
    paam.assignment_type = 'E' and
    paam.person_id = '300000014199145';


    Your intention with the outer join might be:



    select par.PersonID, par.Responsibility_Type 
    from per_asg_responsibilities par left join
    per_all_assignments_m paam
    on paam.assignment_id = par.assignment_id and
    paam.person_id = par.person_id and
    sysdate between nvl(paam.effective_start_date, sysdate) and
    nvl(paam.effective_end_date, sysdate) and
    paam.assignment_type = 'E' and
    where par.person_id = '300000014199145';






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 3 at 16:52









    Gordon LinoffGordon Linoff

    792k36316419




    792k36316419













    • Hi, Thanks for the reply. I have already tried these but still getting same multiple rows. I think I may need to use row_num function

      – shivam
      Jan 3 at 17:10



















    • Hi, Thanks for the reply. I have already tried these but still getting same multiple rows. I think I may need to use row_num function

      – shivam
      Jan 3 at 17:10

















    Hi, Thanks for the reply. I have already tried these but still getting same multiple rows. I think I may need to use row_num function

    – shivam
    Jan 3 at 17:10





    Hi, Thanks for the reply. I have already tried these but still getting same multiple rows. I think I may need to use row_num function

    – shivam
    Jan 3 at 17:10













    0














    Based on your data, you're getting the correct results. All three rows in the par table have the same assignmentId (300000014199240) so will be returned by your query regardless of the join syntax.



    Adding a "Distinct" clause will get you the results you want.



    select DISTINCT
    par.PersonID, par.Responsibility_Type
    from
    per_all_assignments_m paam, per_asg_responsibilities par
    where
    sysdate between nvl(paam.effective_start_date,sysdate) and
    nvl(paam.effective_end_date,sysdate)
    and paam.assignment_type='E'
    and paam.assignment_id = par.assignment_id(+)
    and paam.person_id = '300000014199145';


    I set this up in a SQL Fiddle here http://sqlfiddle.com/#!4/d7b7f/8. Note: I removed the date field references since you didn't give us data for those, but it shouldn't affect the results based on how you described the problem.






    share|improve this answer




























      0














      Based on your data, you're getting the correct results. All three rows in the par table have the same assignmentId (300000014199240) so will be returned by your query regardless of the join syntax.



      Adding a "Distinct" clause will get you the results you want.



      select DISTINCT
      par.PersonID, par.Responsibility_Type
      from
      per_all_assignments_m paam, per_asg_responsibilities par
      where
      sysdate between nvl(paam.effective_start_date,sysdate) and
      nvl(paam.effective_end_date,sysdate)
      and paam.assignment_type='E'
      and paam.assignment_id = par.assignment_id(+)
      and paam.person_id = '300000014199145';


      I set this up in a SQL Fiddle here http://sqlfiddle.com/#!4/d7b7f/8. Note: I removed the date field references since you didn't give us data for those, but it shouldn't affect the results based on how you described the problem.






      share|improve this answer


























        0












        0








        0







        Based on your data, you're getting the correct results. All three rows in the par table have the same assignmentId (300000014199240) so will be returned by your query regardless of the join syntax.



        Adding a "Distinct" clause will get you the results you want.



        select DISTINCT
        par.PersonID, par.Responsibility_Type
        from
        per_all_assignments_m paam, per_asg_responsibilities par
        where
        sysdate between nvl(paam.effective_start_date,sysdate) and
        nvl(paam.effective_end_date,sysdate)
        and paam.assignment_type='E'
        and paam.assignment_id = par.assignment_id(+)
        and paam.person_id = '300000014199145';


        I set this up in a SQL Fiddle here http://sqlfiddle.com/#!4/d7b7f/8. Note: I removed the date field references since you didn't give us data for those, but it shouldn't affect the results based on how you described the problem.






        share|improve this answer













        Based on your data, you're getting the correct results. All three rows in the par table have the same assignmentId (300000014199240) so will be returned by your query regardless of the join syntax.



        Adding a "Distinct" clause will get you the results you want.



        select DISTINCT
        par.PersonID, par.Responsibility_Type
        from
        per_all_assignments_m paam, per_asg_responsibilities par
        where
        sysdate between nvl(paam.effective_start_date,sysdate) and
        nvl(paam.effective_end_date,sysdate)
        and paam.assignment_type='E'
        and paam.assignment_id = par.assignment_id(+)
        and paam.person_id = '300000014199145';


        I set this up in a SQL Fiddle here http://sqlfiddle.com/#!4/d7b7f/8. Note: I removed the date field references since you didn't give us data for those, but it shouldn't affect the results based on how you described the problem.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 18:22









        Mike ParkhillMike Parkhill

        4,67812235




        4,67812235






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026491%2fmultiple-rows-in-spite-of-using-outer-join%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Mossoró

            Can't read property showImagePicker of undefined in react native iOS

            Pushsharp Apns notification error: 'InvalidToken'