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
 Transact-SQL (2000)
 Need help with Query that contains subquery

Author  Topic 

j_mact
Starting Member

17 Posts

Posted - 2007-03-06 : 09:46:12
All,
I have two tables with First,Middle, and Last Names. I want to pull out the names that do not match. I have the query below, but I keep getting a syntax error on the line in bold:

select s.lastname,s.firstname,s.middlename,s.ssn,s.sch,s.code,t.lastname,
t.firstname, t.middlename from teachsims s, teacherhr t where s.ssn = t.ssn and
s.lastname, s.firstname, s.middlename
not in (select t.lastname,t.firstname,t.middlename from teacherhr)

Here is the error I am receiving: Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near ','.


Any help would be appreciated

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-06 : 09:50:56
[code]
select s.lastname,s.firstname,s.middlename,s.ssn,s.sch,s.code,t.lastname,
t.firstname, t.middlename
from teachsims s inner join teacherhr t
on s.ssn = t.ssn
where not exists (select * from teacherhr x
where x.lastname = s.lastname
and x.firstname = s.firstname
and x.middlename = s.middlename)
[/code]


KH

Go to Top of Page

j_mact
Starting Member

17 Posts

Posted - 2007-03-06 : 09:55:51
Thanks!!! It worked like a charm!!!
Go to Top of Page
   

- Advertisement -