Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8161895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:35:43+00:00 2026-06-06T18:35:43+00:00

I used JPA and mysql. Each table have entity class.I have four tables. Table1

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:35:44+00:00Added an answer on June 6, 2026 at 6:35 pm

    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)

        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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Weird stuff... I have happily used EclipseLink / JPA 2 as provider for my
In my project, I've used spring, jpa with PostgreSQL DB, I've lots of table
I use: EJB3 / JPA (Hibernate) MySQL 5 I have to set up a
I have successfully used hibernate3-maven-plugin with Hibernate-Core and EntityManager 3.6.6-FINAL, hibernate-commons-annotations-3.2.0.Final, hibernate-jpa-2.0-api-1.0.1.Final and hibernate-validator-4.0.0.GA
both also used for annotating foreign key in jpa entity right? I do understand
I have made use of the following JPA implementations: Hibernate, Toplink, OpenJPA Each of
I have used Spring DATA JPA in my application, which is wrapper over hibernate.
Hello every body I have used following code in my jpa project for working
Can Hibernate 3.5.x be used as the JPA provider instead of the default provider
I am new to JPA, I used to used prepared statement in JDBC. Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.