Fetching records from the MySQL database from 10 tables
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开发者_如何学C, or write 2 or 3 simple queries? I want to select the better solution for my service.
If the tables are related to each other, I would try using JOINS, they provide better (much better) performance than just using nested queries.
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
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
精彩评论