SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 select rows now found
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

leon1958
Starting Member

India
4 Posts

Posted - 09/08/2013 :  00:24:09  Show Profile  Reply with Quote
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

USA
35954 Posts

Posted - 09/08/2013 :  00:41:25  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

India
4 Posts

Posted - 09/08/2013 :  07:10:46  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000