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
  • 698,132
  • 130
  • 858
  • 1,229
subodh
  • 6,004
  • 12
  • 48
  • 69

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,570
  • 2
  • 28
  • 40
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,232
  • 9
  • 52
  • 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,004
  • 12
  • 48
  • 69
amit sharma
  • 210
  • 2
  • 9