title: Getting Oracle SQL top level parent record from a number of parent/child records
body: <p>I'm trying to create an Oracle SQL statement to get the top root level parent record from a number of parent, child records on different levels. The table structure is below. The top level root parent in the below is parent_membership_id 53887, this parent record has a number of children, who are also parents to other children. What I want is a query that if I query say member of 200326, the query brings back the root member 53887, or if I query 200322 I get root member 53887. I think you know what I'm trying to do. Thanks in adavance.</p>
  
  <pre><code> CREATE TABLE MEMBERSHIP_LINK
   ( MEMBERSHIP_LINK_ID        NUMBER(10)          NOT NULL,
     CHILD_MEMBERSHIP_ID       NUMBER(10)          NOT NULL,
     PARENT_MEMBERSHIP_ID      NUMBER(10)          NOT NULL);
  
  Insert into MEMBERSHIP_LINK
     (MEMBERSHIP_LINK_ID, CHILD_MEMBERSHIP_ID, PARENT_MEMBERSHIP_ID)
   Values
     (35, 53890, 53887);
  Insert into MEMBERSHIP_LINK
     (MEMBERSHIP_LINK_ID, CHILD_MEMBERSHIP_ID, PARENT_MEMBERSHIP_ID)
   Values
     (24475, 200322, 53887);
  Insert into MEMBERSHIP_LINK
     (MEMBERSHIP_LINK_ID, CHILD_MEMBERSHIP_ID, PARENT_MEMBERSHIP_ID)
   Values
     (24476, 200322, 53887);
  Insert into MEMBERSHIP_LINK
     (MEMBERSHIP_LINK_ID, CHILD_MEMBERSHIP_ID, PARENT_MEMBERSHIP_ID)
   Values
     (34, 53889, 53888);
  Insert into MEMBERSHIP_LINK
     (MEMBERSHIP_LINK_ID, CHILD_MEMBERSHIP_ID, PARENT_MEMBERSHIP_ID)
   Values
     (5941, 112177, 53889);
  Insert into MEMBERSHIP_LINK
     (MEMBERSHIP_LINK_ID, CHILD_MEMBERSHIP_ID, PARENT_MEMBERSHIP_ID)
   Values
     (33, 53888, 53890);
  Insert into MEMBERSHIP_LINK
     (MEMBERSHIP_LINK_ID, CHILD_MEMBERSHIP_ID, PARENT_MEMBERSHIP_ID)
   Values
     (24477, 200323, 200322);
  Insert into MEMBERSHIP_LINK
     (MEMBERSHIP_LINK_ID, CHILD_MEMBERSHIP_ID, PARENT_MEMBERSHIP_ID)
   Values
     (24478, 200323, 200322);
  Insert into MEMBERSHIP_LINK
     (MEMBERSHIP_LINK_ID, CHILD_MEMBERSHIP_ID, PARENT_MEMBERSHIP_ID)
   Values
     (24479, 200325, 200323);
  Insert into MEMBERSHIP_LINK
     (MEMBERSHIP_LINK_ID, CHILD_MEMBERSHIP_ID, PARENT_MEMBERSHIP_ID)
   Values
     (24480, 200326, 200323);
  COMMIT;
  </code></pre>