how can compare two columns in different table
Hello friends,
I have two table.
1. StudentAdmissiondetails
column: AdmissionNumber and extra
2. StudentAcadmicdetails
cloumn: AdmissionNumber and extra.
I want to compare two AdmissionNumber column and if AdmisssionNumber in table 1 and not in table 2 mean I want to some task. this task i can do it. two tables may contain many sdmissionNumber. how can i do it.
Sivaraman DhamodaranPosted Nov 27, 2012, 3:51 AM
baskaran chellasamyPosted Nov 27, 2012, 3:50 AM
begin
declare @acid int,@admissionnumber int,@admissionnumber1 int
select @acid=Acadamic_year_id from School.dbo.Acadamic_year where Acadamic_year_from=@fromyear and Acadamic_year_to=@toyear
select sa.AdmissionNumber,sa.StudentName,st.Standered_name from School.dbo.StudentAdmission_details sa inner join School.dbo.Standered_details st on sa.ClassId=st.Standered_id where sa.ClassId=@classid and sa.Academic_year_id=@acid
end
If admissionnumber not exists in studentAcademictable then i want to use the join query.how can do it
Shankar MPosted Nov 27, 2012, 3:43 AM
Here it is, You can get it through the correlated subquery.
Something like this,
SELECT *
FROM StudentAdmissiondetails a
WHERE NOT EXISTS (SELECT 'Y'
FROM StudentAcadmicdetails b
WHERE b.AdmissionNumber=a.AdmissionNumber);
Which will get you all the Admission number that are not in Table B that is your
StudentAcadmicdetails.
Thanks,
Shankar