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 2005 Forums
 Transact-SQL (2005)
 Get Records based on value in second table

Author  Topic 

Steve2106
Posting Yak Master

183 Posts

Posted - 2011-05-17 : 13:21:01
Hi There,

I'm in need of you help again!

I have 2 tables and I need to show all the records in table1 where there is not a record in table2 where the usercall field is equal to 'Complaint'

Table1 & Table2 both have a matching field called UserId
UserId in Table1 is the primarykey, Table2 has multiple records for userid.
Thanks for your help, I appreciate it.

Best Regards,



Steve

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-05-17 : 13:30:57
select <stuff> from table1 t1
where not exists
(select * from table2 t2 where t1.userid = t2.userid and t2.usercall = 'complaint')

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

Steve2106
Posting Yak Master

183 Posts

Posted - 2011-05-18 : 02:58:39
Hi Jim,

Thanks for the reply.

That looks great I'll give it a go.

Thanks for taking the time to help.

Best Regards,



Steve
Go to Top of Page
   

- Advertisement -