MySQL クエリのヘルプが必要です。
以下のスキーマを見つけてください。
Table1
PK_id Table1_Title Table1_Description
1 Test1 This is Test1
2 Test2 This is Test2
Table2
FK_id Table2_Title Table2_Description
1 Test2 This is Test2
1 Test3 This is Test3
ここで、「Table2」はマスターテーブル「Table1」と子関係にあります。上記の2つのテーブルのタイトルと説明の列で検索したい。検索文字列がマスター テーブル "Table1" で見つかった場合、その行と子のすべての行が返されます。同様に、子テーブル行の 1 つで検索文字列が見つかった場合、対応するマスター テーブル行とそのすべての子が返されます。明確にするために、以下の結果を見つけてください。
結果:
Case 1:
If searching TEST2 Then
PK_id Table1_Title Table1_Description FK_id Table2_Title Table2_Description
1 Test1 This is Test1 1 Test2 This is Test2
1 Test1 This is Test1 1 Test3 This is Test3
2 Test2 This is Test2 NULL NULL NULL
Case 2:
If searching TEST1 Then
PK_id Table1_Title Table1_Description FK_id Table2_Title Table2_Description
1 Test1 This is Test1 1 Test2 This is Test2
1 Test1 This is Test1 1 Test3 This is Test3
Case 3:
If searching TEST3 Then
PK_id Table1_Title Table1_Description FK_id Table2_Title Table2_Description
1 Test1 This is Test1 1 Test2 This is Test2
1 Test1 This is Test1 1 Test3 This is Test3
単一のクエリなどで結果を出すことは可能ですか?
助けてください。