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
 General SQL Server Forums
 New to SQL Server Programming
 Compare multiple collumns

Author  Topic 

nnogueira
Starting Member

18 Posts

Posted - 2009-05-25 : 15:21:05
Hello Friends!

I new to sql and i need some help with this:

Consider 2 Databases, tableA and tableB

TableA
Name(Nchar) Number(Nchar) CallerID(Nchar)

name1 ------ Number1 ------ID1
name2 ------ Number2 ------ID2
name3 ------ Number3 ------ID3


TableB
Name(Nchar) Number(Nchar) CallerID(Nchar)

name1 ------ Number1 ------ID1
name2 ------ Number4 ------ID2
name3 ------ Number3 ------ID3


In bold, i mark data that i want to retrieve, thats group of collumns of TableA dont math Table B, the result i want is:

name2 ------ Number2 ------ID2


Someome can help-me ?

Thanks!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-05-25 : 15:25:44
Which column is primary key?


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

nnogueira
Starting Member

18 Posts

Posted - 2009-05-25 : 15:27:18
quote:
Originally posted by Peso

Which column is primary key?


E 12°55'05.63"
N 56°04'39.26"




No one´s is primary key. Some data can be repeated sometimes in this database.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-05-25 : 15:34:54
SELECT t1.Name, t1.Number, t1.CallerID
FROM TableA AS t1
LEFT JOIN TableB AS t2 ON t2.Name = t1.Name AND t2.Number = t1.Number AND t2.CallerID = t1.CallerID
WHERE t2.Name IS NULL


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

nnogueira
Starting Member

18 Posts

Posted - 2009-05-25 : 15:46:42
quote:
Originally posted by Peso

SELECT t1.Name, t1.Number, t1.CallerID
FROM TableA AS t1
LEFT JOIN TableB AS t2 ON t2.Name = t1.Name AND t2.Number = t1.Number AND t2.CallerID = t1.CallerID
WHERE t2.Name IS NULL


E 12°55'05.63"
N 56°04'39.26"




It Works!

Thanks again Peso, u save me!

Go to Top of Page
   

- Advertisement -