473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Order of tables in joins

Sri
I am writing a download process in which i have a condition where i
need to join four tables. Each table have lot of data say around
300000 recs.
my question is when i am doing the joins on the columns is there any
specific order i need to follow.

for example
My original query looks like this

select a.col1,a.col2
from a
inner join b
on a.id1=b.id1
and a.id2=b.id2
inner join c
on c.id1=b.id1
and c.id2=b.id2
inner join d
on d.id1=c.id1
and d.id2=c.id2

If i change the query like below... does it make any difference

select a.col1,a.col2
from a
inner join b
on b.id1=a.id1
and b.id2=a.id2

inner join c
on c.id1=a.id1
and c.id2=a.id2

inner join d
on d.id1=a.id1
and d.id2=a.id2
Any help is appreciated.
Thanks

Sri
Jul 20 '05 #1
4 3973
If your statistics are up to date, then it doesn't matter. The query
optimizer will determine the best join order for you. Ideally you want the
earlier joins to be more selective so that the later joins can have an
easier time.

If your statistics are out of date, then you can either update your
statistics ("update statistics mytable with fullscan"), or determine the
best join order yourself and include a "force order" hint in your select
statement.

Regards,
Dave

"Sri" <sr*******@hotmail.com> wrote in message
news:9b**************************@posting.google.c om...
I am writing a download process in which i have a condition where i
need to join four tables. Each table have lot of data say around
300000 recs.
my question is when i am doing the joins on the columns is there any
specific order i need to follow.

for example
My original query looks like this

select a.col1,a.col2
from a
inner join b
on a.id1=b.id1
and a.id2=b.id2
inner join c
on c.id1=b.id1
and c.id2=b.id2
inner join d
on d.id1=c.id1
and d.id2=c.id2

If i change the query like below... does it make any difference

select a.col1,a.col2
from a
inner join b
on b.id1=a.id1
and b.id2=a.id2

inner join c
on c.id1=a.id1
and c.id2=a.id2

inner join d
on d.id1=a.id1
and d.id2=a.id2
Any help is appreciated.
Thanks

Sri

Jul 20 '05 #2
>> my question is when i am doing the joins on the columns is there
any specific order i need to follow. <<

You don't understand the basic idea of a non-procedural language like
SQL. You tell the compiler what your want and it figures out how to
find it.

In rare cases, if you have a large number of tables of nearly the same
size and indexing, then the optimizer can have so many permutations to
consider that it will make a sub-optimal decision about the order of
using the tables.
Jul 20 '05 #3

"--CELKO--" <jo*******@northface.edu> wrote in message
news:a2**************************@posting.google.c om...
my question is when i am doing the joins on the columns is there

any specific order i need to follow. <<

You don't understand the basic idea of a non-procedural language like
SQL. You tell the compiler what your want and it figures out how to
find it.

In rare cases, if you have a large number of tables of nearly the same
size and indexing, then the optimizer can have so many permutations to
consider that it will make a sub-optimal decision about the order of
using the tables.


Note in SQL 6.5 I believe join order did matter (mostly because the
optimizer wasn't as smart as now.)

These days, I haven't seen any difference in the join order in terms of
performance.

Jul 20 '05 #4
>> Note in SQL 6.5 I believe join order did matter (mostly because the
optimizer wasn't as smart as now.) <<

The magic number in early SQL product was 5 tables. This is also a
human processing limit, too. The reason is that the permutations jump
at five:

tables permutations
====================
1 1
2 2
3 6
4 24
5 120

Oracle used to process tables in the reverse order they appeared in the
FROM clause before they got an optimizer; you could get some really
weird performance from that design flaw. People tended to put the
"minor" tables at the end of the list, so main storage would fill up
with a larger table and the smaller tables would be paged in and out.
Doing it the other way, the smaller tables went into main storage and
stayed there while the larger tables were scanned and paged in.
--CELKO--
===========================
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: | last post by:
As we're on this topic in another thread right now: Say I have a SELECT query from more than one table and with some = conditions, does it matter in what order I enter the tables in the FROM =...
2
by: Paulo Andre Ortega Ribeiro | last post by:
I have a Microsoft SQL Server 7.0. I wrote a sql command that creates a temporary table with a ORDER BY clause. When a execute a SELECT on this temporary table sometimes the result is ok, but...
4
by: GM | last post by:
Does the order in which Joins are peformed (from left to right) matter whether inner or outer when it comes to performance. Assuming that all indexes are the same but the size of the tables is...
2
by: Wenin | last post by:
I have four total tables. Table One (Documents)- List of Documents. Each record has two fields related to this issue. First field (Document_ID) is the ID of the document, second field is the...
3
by: csomberg | last post by:
SQL Server 2000 Howdy All. Is it going to be faster to join several tables together and then select what I need from the set or is it more efficient to select only those columns I need in...
1
by: mailar | last post by:
Hi, Can I use ORDER BY clause in my sql UDF that returns a table and has the folloing body. (trial_udf.sql) drop function aa@ create function aa() returns TABLE(empno varchar(20)) language...
1
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
2
by: Veeru71 | last post by:
Hi, 1) Is it possible to force the join order of the tables in a query (similar to "hints" in Sybase, etc) ? For Example, I am joining 3 tables - A,B & C in my SELECT stmt, and I would like...
3
by: nico3334 | last post by:
I currently have a query that Joins 2 Tables (Table1 and Table2) using LEFT OUTER JOIN. Here is an example of that query: SELECT a.supply, a.state, b.cost FROM Table1 a LEFT...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.