【发布时间】:2012-06-28 02:08:25
【问题描述】:
我使用了 JPA 和 mysql。 每个表都有实体类。我有四个表。
表 1: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:地址表
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 个表包含数据。一张表没有任何数据。
如果数据存在其他表,我需要为“studentId = 2 使用的表名和表计数”编写查询。 否则是否有任何其他逻辑来获取此信息。
就像现在 studentId = 2 使用两个表一样。所以结果是 *(roll_table,address_table)*
假设联系人表有 studentId=2 的数据,
那么结果是 *(roll_table,address_table,contact_table)*
帮帮我。 在此先感谢
【问题讨论】:
-
了解SQL joins:您想使用外连接。
标签: mysql jpa entity primary-key