October 19, 2011 at 5:49 am
Hi Guys
When referring to joins....
There is a left and right table
Where is this specified, in the ON clause or in the select columns list
Thanks
October 19, 2011 at 6:01 am
okbangas (10/19/2011)
Implicit by the order of the tables. The left one is specified before the right one.
Thanks
October 19, 2011 at 6:01 am
Neither, the term left and right are based on the order in which the table appears within the query.
ON a.id = b.id is the same as b.id = a.id and they have no impact in terms of the table being treated as left or right.
The select list is user defined and therefore has no impact in terms of the join. i.e the select column list is the last step and performed when displaying the information in the order specified by the user and therefore not considered at the time of performing a join.
October 19, 2011 at 6:02 am
That's too vague to answer!
What type of join? inner, outer, full?
In the inner join there's no real right or left. They just have to match and the server will then pick the best access path to get the data as fast as possible.
October 19, 2011 at 6:04 am
Ninja's_RGR'us (10/19/2011)
That's too vague to answer!What type of join? inner, outer, full?
In the inner join there's no real right or left. They just have to match and the server will then pick the best access path to get the data as fast as possible.
For a left outer join, the results will be all the matching rows and everything else from the left table, correct?
Which is the left table?
October 19, 2011 at 6:08 am
For a left outer join, the results will be all the matching rows and everything else from the left table, correct?
Which is the left table?
< joined_table > ::=
< table_source > < join_type > < table_source > ON < search_condition >
| < table_source > CROSS JOIN < table_source >
| < joined_table >
< join_type > ::=
[ INNER | { { LEFT | RIGHT | FULL } [ OUTER ] } ]
[ < join_hint > ]
JOIN
SELECT *
FROM LEFT_TABLE LT
LEFT JOIN RIGHT_TABLE RT
ON LT.ID=RT.ID
October 19, 2011 at 6:13 am
derekr 43208 (10/19/2011)
Ninja's_RGR'us (10/19/2011)
That's too vague to answer!What type of join? inner, outer, full?
In the inner join there's no real right or left. They just have to match and the server will then pick the best access path to get the data as fast as possible.
For a left outer join, the results will be all the matching rows and everything else from the left table, correct?
Which is the left table?
+ null values (unmatching records)from right side tables.
Left side is left table
drop table #TableX
drop table #TableY
Create Table #TableX (Date_ int)
Create Table #TableY (YearsBack int)
insert into #TableX values(18)
insert into #TableY values(18)
insert into #TableX values(1)
insert into #TableY values(8)
go
select * from #TableX x left outer join #TableY y
on (x.Date_=y.YearsBack)
select * from #TableY y left outer join #TableX x
on (x.Date_=y.YearsBack)
Muthukkumaran Kaliyamoorthy
https://www.sqlserverblogforum.com/
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply