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

Left join

 
   Database Help (Home) -> Programming RSS
Next:  Problem with SQL Delete Query - 3 tables involved  
Author Message
veerleverbr

External


Since: Jun 30, 2005
Posts: 1



(Msg. 1) Posted: Wed Oct 11, 2006 7:07 am
Post subject: Left join
Archived from groups: microsoft>public>sqlserver>programming (more info?)

On a Sql Server 2005, suppose the query

SELECT ......
FROM A
LEFT JOIN B ON B.Col1 = A.Col2
LEFT JOIN C ON (C.Col3 = A.Col4 OR C.Col5 = B.Col6)

If the left join on B results in 1 or more rows, then I get all the
rows from C: the rows that apply to the first condition and the rows
that apply to the second condition.

If the left join on B results in 0 rows, then I get no rows from C, not
even the ones for which C.Col3 = A.Col4 applies.

How can rewrite this query, so that of there are not B rows applying to
the query, I still get the C rows for C.Col3 = A.Col4? I don't want to
left join with C twice. Is it possible at all to do such a thing?

 >> Stay informed about: Left join 
Back to top
Login to vote
Sylvain Lafontaine1

External


Since: Dec 13, 2003
Posts: 301



(Msg. 2) Posted: Wed Oct 11, 2006 10:37 am
Post subject: Re: Left join [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Last time I had a problem like this one, I used a subquery to first left
join A and B and then used this subquery to left join with C.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF


wrote in message

> On a Sql Server 2005, suppose the query
>
> SELECT ......
> FROM A
> LEFT JOIN B ON B.Col1 = A.Col2
> LEFT JOIN C ON (C.Col3 = A.Col4 OR C.Col5 = B.Col6)
>
> If the left join on B results in 1 or more rows, then I get all the
> rows from C: the rows that apply to the first condition and the rows
> that apply to the second condition.
>
> If the left join on B results in 0 rows, then I get no rows from C, not
> even the ones for which C.Col3 = A.Col4 applies.
>
> How can rewrite this query, so that of there are not B rows applying to
> the query, I still get the C rows for C.Col3 = A.Col4? I don't want to
> left join with C twice. Is it possible at all to do such a thing?
>

 >> Stay informed about: Left join 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
left join/inner join/outer join with repeat values - hi david, thanks for the reply. basically what i need this for is: there are two tables: table1 is a master table, table2 is a detail table. table1's primary_id is present in details_id of table2 table1 has only 1 record table2 could have many..

Left join is equal to inner join? - Hi All I try to calculate the result by using left join but it still returns the output same as using inner join. ************************************ Table1(T1) Status_id Score_id SumOfAmount Chief Excellent 1 Chief Fair 1 Chief ....

LEFT JOIN question - Hi, I have table A and I create a left join to table B: SELECT * from tableA a LEFT JOIN tableB b ON a.id=b.id... and I get all the records from table A, that is 100 records for example. If I create join to table C: SELECT * from tableA a LEFT JOIN....

use "left join" or "not exists" ? - Using SQL Server 2000, Example : == create table jtest1 (id int primary key, col1 varchar(10)) create table jtest2 (id2 int primary key, col2 varchar(10)) insert jtest1 values (1, 'hello') insert jtest1 values (2, 'two') insert jtest2 values (1,..

LEFT OUTER JOIN problem - Hello, I have 2 tables , tblTOSub , and tblTrScanSub with this schema , the 2 identities are the PKeys. CREATE TABLE [dbo].[tblTOSub]( [TOSubID] [int] IDENTITY(1,1) NOT NULL, [TOID] [int] NOT NULL, [ItemID] [int] NOT NULL, [Qty] [int] NOT NULL, ..
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
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 ]