Is there a limit to the number of tables we can join in Oracle?

by jamuna.g
(hyderabad)

Question: How many tables can we join in Oracle?


There is no hard limit on the number of tables that you can join in a single query in Oracle. There is likely to be a limit to your comprehension of a SQL statement that is joining many tables though! The more complex the SQL the harder it is to understand and the harder it is to optimise and to maintain.

Generally, the more tables that are involved in a join in Oracle the slower the query will be as all the data has to be read from the tables (and/or indexes) and then sorted and merged to generate the final result. The more data that needs to be sorted, the more memory is required for sorting and the more likely it is that the sorting will have ti be done on disk (which is slower than doing it in memory).

If you're using PL/SQL then there is a hard limit of about 6,000,000 lines of code (including your embedded SQL statements) and a limit of 254 for sub-query nesting.

A SQL query that requires a large number of tables to be joined may be indicative of a design flaw in your database design for OLTP systems. With Oracle datawarehouses you are likely to see perhaps 6 or more tables being joined in what's known as a star query where a central fact table (sales, for example) is joined with multiple satellite dimension tables such as time, location, organisation, product etc depending on how many dimensions an organisation has.

Therefore, overall there are no practical limits on how many tables you can join in a query in Oracle but joining a large number of tables may lead to performance issues and may indicate that the system and database designs have not been optimised.

For more help see our Oracle SQL tutorials.

If you're interested in formal Oracle training (either on-line or in a classroom) then see our Oracle training page for more information.

Click here to post comments

Join in and write your own page! It's easy to do. How? Simply click here to return to Oracle Questions.