![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
CREATE TABLE [RS_A] ( [ColA] [varchar] (10) [ColB] [int] NULL ) CREATE TABLE [RS_B] ( [ColA] [varchar] (10) [ColB] [int] NULL ) INSERT INTO RS_A VALUES ('hemingway' , 1) INSERT INTO RS_A VALUES ('vidal' , 2) INSERT INTO RS_A VALUES ('dickens' , 3) INSERT INTO RS_A VALUES ('rushdie' , 4) INSERT INTO RS_B VALUES ('hemingway' , 1) INSERT INTO RS_B VALUES ('vidal' , 2) I need to find all the rows in A which do not exist in B by matching on both ColA and ColB so the output should be dickens 3 rushdie 4 So if i write a query like this , I dont get the right result set SELECT A.ColA, A.ColB FROM RS_A A INNER JOIN RS_B B ON A.ColA <> B.ColA OR B.ColB <> B.ColB But if i do the following, i do get the right result, but following seems convoluted. SELECT A.ColA, A.ColB FROM RS_A A WHERE ColA + CAST(ColB AS VARCHAR) NOT IN (SELECT ColA+CAST(ColB AS VARCHAR) FROM RS_B B) |
#3
| |||
| |||
|
#4
| |||
| |||
|
#5
| |||
| |||
|
#6
| |||
| |||
|
|
SELECT A.ColA, A.ColB FROM RS_A A LEFT OUTER JOIN RS_B B ON A.ColA = B.ColA AND B.ColB = B.ColB WHERE B.ColA IS NULL Hi Harvey : I was implementing this solution at another place and i mentioned an AND instead of a WHERE. and it did not work. So i used WHERE and viola, things worked. But actually how can i use a WHERE Clause? I thought WHERE Clauses were for the FROM table and not for the tables that are joined to the FROM table Is my assumption correct ? Obviously it is wrong, So is it a normal thing to mention conditions where only one table is needed(like in the above example) in the WHERE Clause, as then i can do that will all my other queries where i am joining, and i always have mentioned unique conditions pertaining to that table alone, using an AND clause. thank you in advance RS |
#7
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |