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
 General SQL Server Forums
 New to SQL Server Programming
 Finding Unique records in multiple tables

Author  Topic 

oziking
Starting Member

3 Posts

Posted - 2010-08-09 : 04:26:27
Total 3 tables in a database
(Students, Results1, Results2)

Results1 & Results 2 have more than 50000 records

Now I want to compare ID of students (Students Table) to the Results1 and Results2 and show the records which are matching StudentID in Results1 & Results2 only.

If the corresponding result of a particular field is not present in Result1 or Result2, it must print an empty value in the query results

Students
StudentID
Fullname


Results1
StudentID
Fullname
R1
R2


Results2
StudentID
Fullname
R1
R2


I want the results as

Students.Student ID Students.Fullname Results1.R1 Results1.R2 Results2.R1 Results2.R2

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-09 : 04:47:40
Homework question?


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

oziking
Starting Member

3 Posts

Posted - 2010-08-09 : 05:08:10
no not at all
its been ages since i left school
just trying to make my life easier in admissions
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-09 : 05:15:20
[code]SELECT s.StudentID,
s.FullName,
r1.FullName,
r1.R1,
r1.R2,
r2.R1,
r2.R2
FROM dbo.Students AS s
LEFT JOIN dbo.Results1 AS r1 ON r1.StudentID = s.StudentID
LEFT JOIN dbo.Results2 AS r2 ON r2.StudentID = s.StudentID[/code]


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

oziking
Starting Member

3 Posts

Posted - 2010-08-09 : 06:28:04
thanks a lot :)
Go to Top of Page

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2010-08-14 : 04:04:06
(ROFL) this post just made my day :)
Go to Top of Page
   

- Advertisement -