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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
subodh
  • 6,136
  • 12
  • 51
  • 73

3 Answers3

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.

PachinSV
  • 3,680
  • 2
  • 29
  • 41
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

Community
  • 1
  • 1
Matthew Cox
  • 13,566
  • 9
  • 54
  • 72
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
subodh
  • 6,136
  • 12
  • 51
  • 73
amit sharma
  • 210
  • 2
  • 9