Note that there are some explanatory texts on larger screens.

plurals
  1. POFather Son Relation
    primarykey
    data
    text
    <p>I want to design a database which stores the family members and a query can be constructed to find that who is father of whom. In short a father son relationship.</p> <p>This is what I came up with</p> <p><strong>Family</strong> </p> <pre><code>| id | Name | --------------------------- | 1 | Ankit | --------------------------- | 2 | Nishant | ...... </code></pre> <p>and in relation to this to find the relation of son and father I created another table</p> <p><strong>Father</strong></p> <pre><code>| father_id | Son_id | -------------------------------- | 1 | 2 | ------------------------------- ..... </code></pre> <p>I feel its not correct can someone guide me and what query needs to be written to get such a relation.</p> <p>Thanks in advance</p> <p>EDIT</p> <p>ok I tried to the query now but somehow i am getting the error This is what I am doing</p> <pre><code>select f.name as father_name, s.name as son_name from (select family.name from family,father where father.father_id = family.id ) as f Inner Join (select family.name from family,father where father.son_id = family.id) as s on (family.id = father.father_id and family.id = father.son_id) </code></pre> <p>the error is</p> <pre><code>Msg 4104, Level 16, State 1, Line 2 The multi-part identifier "family.id" could not be bound. Msg 4104, Level 16, State 1, Line 2 The multi-part identifier "father.father_id" could not be bound. Msg 4104, Level 16, State 1, Line 2 The multi-part identifier "family.id" could not be bound. Msg 4104, Level 16, State 1, Line 2 The multi-part identifier "father.son_id" could not be bound. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload