RE: Reg. Implementing Join with Not in Condition

RE: Reg. Implementing Join with Not in Condition

 

  

Here is an SQL with the join data but you will ever get a Train row
returned under this format.

SELECT Distinct s.st_name,
s.st_Id,
t.trng_name
FROM Station s
Left Outer Join train t
on s.stn_Id = t.trng_Id
where t.trng_tra_Id='111'
and not exists
(select 1 from Train t2
where t2.trng_tra_Id='111'
and s.stn_Id = t2.trng_Id)



I would use this instead:

SELECT Distinct s.st_name,
s.st_Id
FROM Station s
where not exists
(select 1 from Train t
where t.trng_tra_Id='111'
and s.stn_Id = t.trng_Id)




-----Original Message-----
From: SangeethaPriya R.
[mailto:db2udbdba-ezmlmshield-x57146534.[Email address protected]
Sent: Tuesday, October 30, 2007 6:52 AM
To: LazyDBA Discussion
Subject: Reg. Implementing Join with Not in Condition



Hi All,

Please tell me how to replace the following sql query into sql-join for
the following query.

SELECT Distinct s.st_name,
s.st_Id
FROM Station s
WHERE s.stn_Id not in
(select t.trng_Id from Train t where t.trng_tra_Id='111')

The above query feches the rows: 272


I tried to convert like below. But the result shows it different from
the above query.

SELECT Distinct s.st_name,
s.st_Id
FROM Station s
Left Outer Join train t
on s.stn_Id = t.trng_Id
and t.trng_tra_Id='111'

The above query fetches 274 rows (ie., all the rows in Station s
table.).

Please Help me on this.

Thanks in Advance,

Regards,
R. Sangeetha Priya



---------------------------------------------------------------------
TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
To post a dba job: http://jobs.lazydba.com
To Subscribe : http://www.LazyDBA.com
To unsubscribe: http://www.lazydba.com/unsubscribe.html


DB2 & UDB email list listserv db2-l LazyDBA home page