Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
RIght outer join Problems
Message
From
21/12/2005 13:43:56
 
 
To
21/12/2005 11:30:40
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01079896
Message ID:
01079956
Views:
18
>I am trying to create a select statement in Query Analyzer to join two tables together and get all of the rows from the second table and the matching rows from the first table. Here is what I have come up with:
>
>select b.township, b.range, b.section, b.stand, a.a, a.b, a.c, a.d, a.e, a.g, a.h, a.j,
>a.k, a.l, a.m, a.n, a.o, a.p, a.s, a.t, a.w, a.hardwood, a.softwood, a.total
>from lis_vol a right join InvStds b on
>a.township+a.range+a.section+a.stand = b.township+b.range+b.section+b.stand
>order by b.township+b.range+b.section+b.stand
>
>The problems I am having is that it returns 9009 rows instead of 8999 which is the row count in the right table. In theory it should only return 8999 rows. What am I missing?

It is normally wrong to compare concat varchar,
also because SQL cannot optimize the join
( except if you have an index on a computed field )
select b.township, b.range, b.section, b.stand, a.a, a.b, a.c, a.d, a.e, a.g, a.h, a.j,
a.k, a.l, a.m, a.n, a.o, a.p, a.s, a.t, a.w, a.hardwood, a.softwood, a.total
from lis_vol a right join InvStds b on
a.township =b.township
and
a.range = b.range
and
...
order by b.township,b.range,b.section,b.stand
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform