Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Question on anatomy of a query

 
Goto page Previous  1, 2
   Database Forums (Home) -> Programming RSS
Next:  multiply string with a comma  
Author Message
planb

External


Since: Nov 24, 2004
Posts: 3



(Msg. 16) Posted: Thu Aug 12, 2010 7:25 pm
Post subject: Re: Question on anatomy of a query [Login to view extended thread Info.]
Archived from groups: microsoft>public>sqlserver>programming (more info?)

In article , tshad
wrote:

> Right
>
> but would:
> A JOIN B
> B JOIN C
> C JOIN D
>
> be the same thing as
> A JOIN B
> C JOIN D
> B JOIN C
>
> If so, the 3rd join IS NOT joining against the previous result set.

The above syntax isn't close to valid (no join conditions, no commas to
indicate cross joins), but any way you look at it, the results are the
same (although performance could vary)


select *
from A
inner join B on a.x = b.x
inner join C on b.y = c.y
inner join D on c.z = d.z

Previous results are used at each step.

or

select *
from A
inner join B on a.x = b.x
inner join (select * C inner join D on c.z = d.z) CJ on b.y = CJ.y

Result of A/B combined with results C/D on condition b.y=c.y Because
of the b.y=c.y join condition it doesn't matter how many c/d records
there are, all except the ones that match with b are discarded, because
the c/d condition is the same either way, you get the same number of
records in the end.

The only way it would make a difference is if you meant

select *
from A
cross join B
cross join C
cross join D
cross join B
cross join C


Where you have cartesian joins, and include B and C twice. If you
don't include tables more than once, then cross join or inner join or a
mixture of the two, as long as the same conditions are applied you'll
end up with the same result set.

--
J.B. Moreno

 >> Stay informed about: Question on anatomy of a query 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Query question - I have 2 tables. One table (sales) has a salesid and sales amount. The other table (salesrep) has a salesid and name. I want to write a query that will return the max sales amount and the name of the salerep who's responsible for it. The following..

SQL Query Question - I wrote a stored procedure that uses a cursor and a temp table to return values. I would like to change this to a single query if it is possible to improve performance. The source data looks like this. Sorted by ID then DateValue. ID ...

aggregate query question - I have a recurring pattern in my queries that I am solving by using CTEs and temp tables and am just wondering if there is a better way. I continually have to extract min or max values that occurred between 2 dates but in addition to the min or max I...

Date query question - Hello All, I would like to get all the records in a table with the date = 8/15/08. The date field is dpolltime which is a datetime field.Here is my query SELECT TOP (100) PERCENT AVG(dbo.StatisticalNumeric.nValue_Avg) AS avg_value,..

Query question with 3 FKs - Novice Query question: I have a table with 3 foreign keys, for example: Notes ID as int CreatedBy int ;FK User_table.ID AssignedTo int ;FK User_table.ID ClosedBy int ;FK User_table.ID Note nvarchar(max) and a talbe of users, for example ....
   Database Forums (Home) -> Programming All times are: Pacific Time (US & Canada)
Goto page Previous  1, 2
Page 2 of 2

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]