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.
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 database2Both 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 advanceDurgesh 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 syntaxEm |
 |
|
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 issueI have two table tbl1col1 col2 col3 --composite primary key col1,col2tbl2col1 col2 col3 --composite primary key col1,col2wherein col1 is primary key of tbl_col1and col2 is primary key of tbl_col2i am using the following query to get the excess rowsselect * 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 notHelp meDurgesh J |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-17 : 05:43:26
|
Tryselect * from tbl1 as t1 where not exists(select * from tbl2 where col1=t1.col1 and col2=t1.col2)MadhivananFailing to plan is Planning to fail |
 |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-10-17 : 05:54:37
|
using left join...select t1.*from table1 t1left join table2 t2 on t1.col1 = t2.col2 and t1.col1 = t2.col2where t2.col1 is null and t2.col2 is nullEm |
 |
|
|
|
|