Q
Problem solve Get help with specific problems with your technologies, process and projects.

Which query is better?

Given the queries, which is coded best?

 Select a.field1, a.field2, b.field3, c.field4 from
 a,b,c,d
 where a.id = 'en'
 and b.id = a.id
 and c.id = b.id 
 and d.id = c.id 
or
 
 Select a.field1, a.field2, b.field3, c.field4 from
 a,b,c,d
 where a.id = 'en'
 and b.id = 'en'
 and c.id = 'en'
 and d.id = 'en'
 
I've always opted for 1, but I can't explain why...

As you are aware, both queries are functionally equivalent. The first query is performing a join operation. The second query is performing a cartesian product, and then throwing out those rows which in essence, won't participate in a join. Cartesian products are poor performing creatures under many circumstances. So if possible, go with the first query. The Oracle Optimizer is well equipped to handle joins of various types.

For More Information


Dig Deeper on Oracle database design and architecture

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close