Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 can anybody help me to solve this issue

Author  Topic 

DURGESH
Posting Yak Master

105 Posts

Posted - 2008-10-17 : 04:24:35
hi all,
i have two tables tbl1 in database1 and tbl2 in database2
Both the table have same structure with composite primary key,
but one table is having 20 records and another is having 10 records.
Now my question is "How to find the 10 extra records that r available in tbl1 of database1"

thanks in advance


Durgesh j

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-10-17 : 04:27:05
have a look in books online for LEFT JOIN. have a go at it, and if you struggle come back for some help with the syntax

Em
Go to Top of Page

DURGESH
Posting Yak Master

105 Posts

Posted - 2008-10-17 : 05:38:21
i have gone through Left Outer join but does not solve the issue
I have two table
tbl1
col1 col2 col3 --composite primary key col1,col2
tbl2
col1 col2 col3 --composite primary key col1,col2
wherein col1 is primary key of tbl_col1
and col2 is primary key of tbl_col2
i am using the following query to get the excess rows
select * from tbl1 where col1 not in(select col1 from tbl2) and
col2 not in(select col2 from tbl2)
Is is the right query to solve the issue or not

Help me

Durgesh J
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-17 : 05:43:26
Try

select * from tbl1 as t1
where not exists(select * from tbl2 where col1=t1.col1 and col2=t1.col2)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-10-17 : 05:54:37
using left join...

select t1.*
from table1 t1
left join table2 t2
on t1.col1 = t2.col2 and t1.col1 = t2.col2
where t2.col1 is null
and t2.col2 is null

Em
Go to Top of Page
   

- Advertisement -