私はそれが古いスレッドであることを知っていますが、まだ関連しています。
メアリーとジョンが結婚していて、ジェーンとマットの 2 人の子供がいるとしましょう...
このテーブル構造はどうですか:
side1 | side1type | side2type | side2
----------------------------------------------------
Mary | wife | husband | John
Jane | child | mother | Mary
Jane | child | father | John
Matt | child | mother | Mary
Matt | child | father | John
Jane | sister | brother | Matt
1 人の親戚を見つけたい場合、列 side1 でその人を検索し、次に列 side2 でその人を検索する 2 つのクエリを実行できます...
または、アプリケーションでロジックを使用するよりも、1 つまたは別の列でその人を探す 1 つのクエリで、次のようになります。
If that person has been found in side1 column
we print side1, side1type, "of ", side2
メアリーはジョンの妻
If that person has been found in side2 column
we print side2, side2type, "of ", side1
メアリーはジェーンの母
メアリーはマットの母
それとももっとエレガント...
If that person has been found in side1 column
we print side2 (side2type)
ジョン(夫)
If that person has been found in side2 column
we print side1 (side1type)
ジェーン(子供)
マット(子供)