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)
 select rows now found

Author  Topic 

leon1958
Starting Member

4 Posts

Posted - 2013-09-08 : 00:24:09
Dear Friends in SQL,

I have two temporary tables, one a Master with the key columns as
subject name and
subject id

I have another transaction table where the main key column is subjectid

I want to extract only those subject id's which are not there in the transaction, but there in the master.

What is below is only a simplified version of my actual code, but it will serve the purpose.

Master table
SubjectId Subject Name
01 English
02 Hindi
03 Marathi
04 Maths

Transaction Table
Subjectid Studentid
02 10001
02 10002
04 10001

My select or code should give me the subjectids 01 and 03

Please help!!

Leon



SunPower

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-09-08 : 00:41:25
select * from [Master] m where not exists (select * from [Transaction] t where t.Subjectid = m.SubjectId)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

leon1958
Starting Member

4 Posts

Posted - 2013-09-08 : 07:10:46
Thank you Tara Kizer, it works

Leon


quote:
Originally posted by tkizer

select * from [Master] m where not exists (select * from [Transaction] t where t.Subjectid = m.SubjectId)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



SunPower
Go to Top of Page
   

- Advertisement -