try this...
SELECT t1.A1, t2.B1, t3.C1, t4.D1
FROM t3 LEFT OUTER JOIN
t2 ON t3.C = t2.B FULL OUTER JOIN
t1 ON t2.B = t1.A FULL OUTER JOIN
t4 ON t1.A2 = t4.D
-----Original Message-----
From: Naveen Nahata [mailto:[Email Address Removed] Wednesday, June 25, 2003 5:53 PM
To: LazyDBA.com Discussion
Subject: Outer-Join Problem - An Easy Question
Hi All,
I'm from the oracle land and am having a problem in writing a simple outer
join query in SQL Server.
I'm simplifying the problem with the help of these test tables.
CREATE TABLE t1(A VARCHAR(10), A1 VARCHAR(10), A2 VARCHAR(10));
CREATE TABLE t2(B VARCHAR(10), B1 VARCHAR(10));
CREATE TABLE t3(C VARCHAR(10), C1 VARCHAR(10));
CREATE TABLE t4(D VARCHAR(10), D1 VARCHAR(10));
INSERT INTO t1 VALUES ('A', 'AA', 'AAAA');
INSERT INTO t1 VALUES (null, 'AAAA', 'AAAA');
INSERT INTO t2 VALUES ('A', 'BB');
INSERT INTO t3 VALUES ('A', 'CC');
INSERT INTO t4 VALUES ('AAAA', 'DD');
Table t1 refers to t2(through a) and t4(through a2) directly and t2 refers
to
t3(through b).
I want to join t1 to t2, t3, t4 and retrieve all the rows inside t1
irrespective of whether the value is there in the other tables or
not(outer-join of course)
I wrote this query in Oracle and it works
SQL> SELECT a1, b1, c1, d1
2 FROM t1, t2, t3, t4
3 WHERE t1.a = t2.b(+)
4 AND t2.b = t3.c(+)
5 AND t1.a2 = t4.d
6 /
A1 B1 C1 D1
---------- ---------- ---------- ----------
AA BB CC DD
AAAA DD
I substituted the "+" with the "*" to use it in SQL Server which made my
query look like this:
SELECT a1, b1, c1, d1
FROM t1, t2, t3, t4
WHERE t1.a =* t2.b
AND t2.b =* t3.c
AND t1.a2 = t4.d
But it fails with the error:
"The table 't1' is an inner member of an outer-join clause. This is not
allowed if the table also participates in a regular join clause."
How to overcome this? Or is the query wrong?
Regards
Naveen
DISCLAIMER:
This message (including attachment if any) is confidential and may be
privileged. Before opening attachments please check them for viruses and
defects. MindTree Consulting Private Limited (MindTree) will not be
responsible for any viruses or defects or any forwarded attachments
emanating either from within MindTree or outside. If you have received this
message by mistake please notify the sender by return e-mail and delete
this message from your system. Any unauthorized use or dissemination of this
message in whole or in part is strictly prohibited. Please note that
e-mails are susceptible to change and MindTree shall not be liable for any
improper, untimely or incomplete transmission.
---------------------------------------------------------------------
TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
To unsubscribe, e-mail: mssqldba-[Email Address Removed] additional commands, e-mail: mssqldba-[Email Address Removed]MS Sql Server LazyDBA home page