I used JPA and mysql.
Each table have entity class.I have four tables.
Table1 : student_table
studentId(PK), studentName
1 jack
2 robert
3 tom
4 smith
Table2: roll_table
rollId(PK), studentId(FK)
10001 1
10002 2
10003 3
10004 4
Table3: address_table
addressId(PK) City studentId(FK)
1 Washngton 1
2 NewYork1 2
3 Newyork2 3
4 Wasington2 4
Table4: contact_table
------------------------------------------------
contactId(pk) phoneNumber email studentId(FK)
------------------------------------------------
----------------------------------------------
Base table is ‘student_table’. ‘studentId’ is primary key for this table.
The remaining 3 table have used this studentId as foreign key.
Totally 3 table contains data. one table doesn’t have any data.
I need to write query for “studentId = 2 used table names and tables count if data exist other tables.
otherwise is there Any other logic to get this information.
Like now the studentId = 2 used two tables. So the result is *(roll_table,address_table)*
Suppose contact table have data with studentId=2,
then the result is *(roll_table,address_table,contact_table)*
Help me.
Thanks in advance
try left join which help you to display all the records from lefttable(studentName), even there are no matches on right table(roll_table,address_table,contact_table)