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
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
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