家族を格納するデータベースを設計したいのですが、クエリを作成して、誰が誰の父親であるかを見つけることができます。要するに父子関係。
これが私が思いついたものです
家族
| id | Name |
---------------------------
| 1 | Ankit |
---------------------------
| 2 | Nishant |
......
これに関連して、息子と父親の関係を見つけるために、別のテーブルを作成しました
お父さん
| father_id | Son_id |
--------------------------------
| 1 | 2 |
-------------------------------
.....
誰かが私を導くことができ、そのような関係を得るためにどのクエリを書く必要があるかは正しくないと思います。
前もって感謝します
編集
わかりました今クエリを実行しようとしましたが、どういうわけかエラーが発生していますこれは私がやっていることです
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)
エラーは
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.