How to query parents, maternal grandmother, and paternal grandfather?

Why do I get two different answers for this counting problem?

tikz: show 0 at the axis origin

can i play a electric guitar through a bass amp?

Replacing matching entries in one column of a file by another column from a different file

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?

Test whether all array elements are factors of a number

Did Shadowfax go to Valinor?

What's the point of deactivating Num Lock on login screens?

Is a tag line useful on a cover?

Why, historically, did Gödel think CH was false?

Why does Kotter return in Welcome Back Kotter?

How is it possible to have an ability score that is less than 3?

I'm planning on buying a laser printer but concerned about the life cycle of toner in the machine

Do I have a twin with permutated remainders?

How to format long polynomial?

Why can't I see bouncing of a switch on an oscilloscope?

Email Account under attack (really) - anything I can do?

Have astronauts in space suits ever taken selfies? If so, how?

Approximately how much travel time was saved by the opening of the Suez Canal in 1869?

Theorems that impeded progress

Characters won't fit in table

Watching something be written to a file live with tail

Font hinting is lost in Chrome-like browsers (for some languages )

Is it unprofessional to ask if a job posting on GlassDoor is real?



How to query parents, maternal grandmother, and paternal grandfather?







.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















(Oracle SQL)



I have been trying to figure out this problem on and off for a couple of days now, and it is driving me nuts. I don't have much experience with joins, or SQL in general, but I have gotten really close to solving this.





Two tables, Person and Parent.



Person has columns Person (primary key), Name, and Gender.



Parent has foreign key reference columns Person and Parent.



I didn't make the column names, it is just a part of the assignment.





This is the closest I have gotten:



SELECT Grandchild.Name AS Grandchild, Mother.Name AS Mother, Grandmother.Name AS Grandmother, Father.Name AS Father, Grandfather.Name AS Grandfather
FROM Parent Grandchild_
LEFT JOIN Person Grandchild ON (Grandchild.Person = Grandchild_.Person)
LEFT JOIN Person Mother ON (Grandchild_.Parent = Mother.Person AND Mother.Gender = 'F')
LEFT JOIN Person Father ON (Grandchild_.Parent = Father.Person AND Father.Gender = 'M')
LEFT JOIN Parent Mother_ ON (Mother_.Person = Mother.Person)
LEFT JOIN Parent Father_ ON (Father_.Person = Father.Person)
LEFT JOIN Person Grandmother ON (Grandmother.Person = Mother_.Parent AND Grandmother.Gender = 'F')
LEFT JOIN Person Grandfather ON (Grandfather.Person = Father_.Parent AND Grandfather.Gender = 'M')
WHERE COALESCE (Grandfather.Person, Grandmother.Person) IS NOT NULL




This has returned everything correctly, EXCEPT it doesn't combine the two "halves" of the mom's side and dad's side. There are two rows for each grand kid. Example output:



GRANDCHILD      MOTHER        GRANDMOTHER       FATHER      GRANDFATHER
Mark Marina Linda - -
Kelvin Marina Linda - -
Nathanial Marina Linda - -
Adrian Marina Linda - -
Catlin Samantha Linda - -
Dominique Samantha Linda - -
Mark - - Jackson John
Kelvin - - Jackson John


I don't know how to combine the two parents/grandparents (when available) while also keeping them linked to the child.



So the desired output would be the same, except in instances such as "Mark" and "Kelvin" where it should output:



GRANDCHILD      MOTHER        GRANDMOTHER       FATHER      GRANDFATHER
Mark Marina Linda Jackson John
Kelvin Marina Linda Jackson John


Does anyone know how to accomplish that and/or do this in a much simpler way? I feel like I am using so many joins when I don't need that many, but who knows.









share





























    0















    (Oracle SQL)



    I have been trying to figure out this problem on and off for a couple of days now, and it is driving me nuts. I don't have much experience with joins, or SQL in general, but I have gotten really close to solving this.





    Two tables, Person and Parent.



    Person has columns Person (primary key), Name, and Gender.



    Parent has foreign key reference columns Person and Parent.



    I didn't make the column names, it is just a part of the assignment.





    This is the closest I have gotten:



    SELECT Grandchild.Name AS Grandchild, Mother.Name AS Mother, Grandmother.Name AS Grandmother, Father.Name AS Father, Grandfather.Name AS Grandfather
    FROM Parent Grandchild_
    LEFT JOIN Person Grandchild ON (Grandchild.Person = Grandchild_.Person)
    LEFT JOIN Person Mother ON (Grandchild_.Parent = Mother.Person AND Mother.Gender = 'F')
    LEFT JOIN Person Father ON (Grandchild_.Parent = Father.Person AND Father.Gender = 'M')
    LEFT JOIN Parent Mother_ ON (Mother_.Person = Mother.Person)
    LEFT JOIN Parent Father_ ON (Father_.Person = Father.Person)
    LEFT JOIN Person Grandmother ON (Grandmother.Person = Mother_.Parent AND Grandmother.Gender = 'F')
    LEFT JOIN Person Grandfather ON (Grandfather.Person = Father_.Parent AND Grandfather.Gender = 'M')
    WHERE COALESCE (Grandfather.Person, Grandmother.Person) IS NOT NULL




    This has returned everything correctly, EXCEPT it doesn't combine the two "halves" of the mom's side and dad's side. There are two rows for each grand kid. Example output:



    GRANDCHILD      MOTHER        GRANDMOTHER       FATHER      GRANDFATHER
    Mark Marina Linda - -
    Kelvin Marina Linda - -
    Nathanial Marina Linda - -
    Adrian Marina Linda - -
    Catlin Samantha Linda - -
    Dominique Samantha Linda - -
    Mark - - Jackson John
    Kelvin - - Jackson John


    I don't know how to combine the two parents/grandparents (when available) while also keeping them linked to the child.



    So the desired output would be the same, except in instances such as "Mark" and "Kelvin" where it should output:



    GRANDCHILD      MOTHER        GRANDMOTHER       FATHER      GRANDFATHER
    Mark Marina Linda Jackson John
    Kelvin Marina Linda Jackson John


    Does anyone know how to accomplish that and/or do this in a much simpler way? I feel like I am using so many joins when I don't need that many, but who knows.









    share

























      0












      0








      0








      (Oracle SQL)



      I have been trying to figure out this problem on and off for a couple of days now, and it is driving me nuts. I don't have much experience with joins, or SQL in general, but I have gotten really close to solving this.





      Two tables, Person and Parent.



      Person has columns Person (primary key), Name, and Gender.



      Parent has foreign key reference columns Person and Parent.



      I didn't make the column names, it is just a part of the assignment.





      This is the closest I have gotten:



      SELECT Grandchild.Name AS Grandchild, Mother.Name AS Mother, Grandmother.Name AS Grandmother, Father.Name AS Father, Grandfather.Name AS Grandfather
      FROM Parent Grandchild_
      LEFT JOIN Person Grandchild ON (Grandchild.Person = Grandchild_.Person)
      LEFT JOIN Person Mother ON (Grandchild_.Parent = Mother.Person AND Mother.Gender = 'F')
      LEFT JOIN Person Father ON (Grandchild_.Parent = Father.Person AND Father.Gender = 'M')
      LEFT JOIN Parent Mother_ ON (Mother_.Person = Mother.Person)
      LEFT JOIN Parent Father_ ON (Father_.Person = Father.Person)
      LEFT JOIN Person Grandmother ON (Grandmother.Person = Mother_.Parent AND Grandmother.Gender = 'F')
      LEFT JOIN Person Grandfather ON (Grandfather.Person = Father_.Parent AND Grandfather.Gender = 'M')
      WHERE COALESCE (Grandfather.Person, Grandmother.Person) IS NOT NULL




      This has returned everything correctly, EXCEPT it doesn't combine the two "halves" of the mom's side and dad's side. There are two rows for each grand kid. Example output:



      GRANDCHILD      MOTHER        GRANDMOTHER       FATHER      GRANDFATHER
      Mark Marina Linda - -
      Kelvin Marina Linda - -
      Nathanial Marina Linda - -
      Adrian Marina Linda - -
      Catlin Samantha Linda - -
      Dominique Samantha Linda - -
      Mark - - Jackson John
      Kelvin - - Jackson John


      I don't know how to combine the two parents/grandparents (when available) while also keeping them linked to the child.



      So the desired output would be the same, except in instances such as "Mark" and "Kelvin" where it should output:



      GRANDCHILD      MOTHER        GRANDMOTHER       FATHER      GRANDFATHER
      Mark Marina Linda Jackson John
      Kelvin Marina Linda Jackson John


      Does anyone know how to accomplish that and/or do this in a much simpler way? I feel like I am using so many joins when I don't need that many, but who knows.









      share














      (Oracle SQL)



      I have been trying to figure out this problem on and off for a couple of days now, and it is driving me nuts. I don't have much experience with joins, or SQL in general, but I have gotten really close to solving this.





      Two tables, Person and Parent.



      Person has columns Person (primary key), Name, and Gender.



      Parent has foreign key reference columns Person and Parent.



      I didn't make the column names, it is just a part of the assignment.





      This is the closest I have gotten:



      SELECT Grandchild.Name AS Grandchild, Mother.Name AS Mother, Grandmother.Name AS Grandmother, Father.Name AS Father, Grandfather.Name AS Grandfather
      FROM Parent Grandchild_
      LEFT JOIN Person Grandchild ON (Grandchild.Person = Grandchild_.Person)
      LEFT JOIN Person Mother ON (Grandchild_.Parent = Mother.Person AND Mother.Gender = 'F')
      LEFT JOIN Person Father ON (Grandchild_.Parent = Father.Person AND Father.Gender = 'M')
      LEFT JOIN Parent Mother_ ON (Mother_.Person = Mother.Person)
      LEFT JOIN Parent Father_ ON (Father_.Person = Father.Person)
      LEFT JOIN Person Grandmother ON (Grandmother.Person = Mother_.Parent AND Grandmother.Gender = 'F')
      LEFT JOIN Person Grandfather ON (Grandfather.Person = Father_.Parent AND Grandfather.Gender = 'M')
      WHERE COALESCE (Grandfather.Person, Grandmother.Person) IS NOT NULL




      This has returned everything correctly, EXCEPT it doesn't combine the two "halves" of the mom's side and dad's side. There are two rows for each grand kid. Example output:



      GRANDCHILD      MOTHER        GRANDMOTHER       FATHER      GRANDFATHER
      Mark Marina Linda - -
      Kelvin Marina Linda - -
      Nathanial Marina Linda - -
      Adrian Marina Linda - -
      Catlin Samantha Linda - -
      Dominique Samantha Linda - -
      Mark - - Jackson John
      Kelvin - - Jackson John


      I don't know how to combine the two parents/grandparents (when available) while also keeping them linked to the child.



      So the desired output would be the same, except in instances such as "Mark" and "Kelvin" where it should output:



      GRANDCHILD      MOTHER        GRANDMOTHER       FATHER      GRANDFATHER
      Mark Marina Linda Jackson John
      Kelvin Marina Linda Jackson John


      Does anyone know how to accomplish that and/or do this in a much simpler way? I feel like I am using so many joins when I don't need that many, but who knows.







      oracle join





      share












      share










      share



      share










      asked 3 mins ago









      a8d9add11bff124c0fbddd7a6607a8d9add11bff124c0fbddd7a6607

      12




      12






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "182"
          };
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2fdba.stackexchange.com%2fquestions%2f234101%2fhow-to-query-parents-maternal-grandmother-and-paternal-grandfather%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Database Administrators Stack Exchange!


          • 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%2fdba.stackexchange.com%2fquestions%2f234101%2fhow-to-query-parents-maternal-grandmother-and-paternal-grandfather%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

          Parapolítica Índice Antecedentes El escándalo Proceso judicial Consecuencias Véase...

          How to remove border from elements in the last row?Targeting flex items on the last rowHow to vertically wrap...

          Tecnologías entrañables Índice Antecedentes Desarrollo Tecnologías Entrañables en la...