1

I have a database with 20 tables inside it. I want to fetch records from 10 related tables at a time, and I am using Hibernate. What is the best solution: to write a single query using join with select, or write 2 or 3 simple queries? I want to select the better solution for my service.

3 Answers 3

1

If the tables are related to each other, I would try using JOINS, they provide better (much better) performance than just using nested queries.

Sign up to request clarification or add additional context in comments.

Comments

1

Perform Inner joins as often as possible when looking to combine data from multiple tables. From what I understand they are more efficient than outer joins.

INNER JOIN vs LEFT JOIN performance in SQL Server

This post goes in depth to explaining the reasons why.

GL

Comments

0

Try to use, like

 select * from producer inner join director on director .entityId = producer.producerId left outer join name on director .entityId = name.entityId left outer join address on director .entityId = address.entityId left outer join phone on director .entityId = phone.entityId left outer join email on director .entityId = email.entityId where producerId = 1 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.