0

JPAとmysqlを使用しました。各テーブルにはエンティティ クラスがあります。4 つのテーブルがあります。

Table1 : student_table

studentId(PK), studentName 
1              jack
2              robert
3              tom
4              smith   

表 2: roll_table

rollId(PK), studentId(FK) 
10001          1
10002          2
10003          3
10004          4

表 3: address_table

addressId(PK)  City          studentId(FK) 
1               Washngton       1
2               NewYork1        2
3               Newyork2        3
4               Wasington2      4

表 4: contact_table

------------------------------------------------
contactId(pk) phoneNumber email studentId(FK) 
------------------------------------------------

----------------------------------------------

ベーステーブルは「student_table」です。「studentId」は、このテーブルの主キーです。

残りの 3 つのテーブルは、この StudentId を外部キーとして使用しています。全部で 3 つのテーブルにデータが含まれています。1 つのテーブルにはデータがありません。

"studentId = 2 used table names and tables count if data exist other tables. それ以外の場合、この情報を取得する他のロジックはありますか?

今のように、studentId = 2 は 2 つのテーブルを使用しました。結果は *(roll_table,address_table
)*

助けて。前もって感謝します

4

2 に答える 2

0

右のテーブル (roll_table、a​​ddress_table、contact_table) に一致するものがない場合でも、左のテーブル (studentName) からすべてのレコードを表示するのに役立つ左結合を試してください。

    SELECT student_table.studentId,student_table.studentName
 FROM student_table
 LEFT JOIN roll_table ON student_table.studentId = roll_table.studentId
 LEFT JOIN address_table ON student_table.studentId = address_table.studentId
 LEFT JOIN contact_table ON student_table.studentId = contact_table.studentId
于 2012-06-28T02:31:28.530 に答える
0

このクエリを試してください

SELECT * FROM information_schema.KEY_COLUMN_USAGE 
         WHERE REFERENCED_TABLE_NAME = 'Your base table name'
         AND TABLE_SCHEMA='DataBaseName' 
         AND REFERENCED_COLUMN_NAME = 'coloumnName'

 SELECT * FROM information_schema.KEY_COLUMN_USAGE 
         WHERE REFERENCED_TABLE_NAME = 'student_table'
         AND TABLE_SCHEMA='student_dataBase' 
         AND REFERENCED_COLUMN_NAME = 'studentId'
于 2012-06-28T06:53:34.483 に答える