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.
| Author |
Topic |
|
n3xus
Starting Member
6 Posts |
Posted - 2011-04-29 : 07:42:40
|
| [CODE]Grade_table******************Student_ID | Grade------------------t106 | 100t107 | 85t108 | 75t109 | 60[/CODE][CODE]Student_archive*******************Student_ID | Gender-------------------t106 | Malet109 | Female[/CODE][CODE]StudentStudent_ID | Gender*******************t108 | Femalet107 | Male[/CODE]Now I need to Join 3 tables which would look like following[CODE]Student_ID | Gender | Grade---------------------------t106 | Male | 100t107 | Male | 85t108 | Female | 75t109 | Female | 60[/CODE]I believe I should check for ISNULL and if it's NULL select gender From other tables. But I think there are smarter people in this forum than me who would have better Idea.Any help? |
|
|
n3xus
Starting Member
6 Posts |
Posted - 2011-04-29 : 07:57:34
|
| [code]SELECT * FROM Grade_tableLEFT OUTER JOIN(SELECT Student_ID, Gender FROM StudentUNION ALLSELECT Student_ID, Gender FROM Student_archive) As StudentsON Grade_table.Student_id = Students.Student_ID[/code]Got it. |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-04-29 : 07:59:06
|
| Try unioning the Student_Archive and Student tables and then joining to that union.JimEveryday I learn something that somebody else already knew |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-04-29 : 08:08:58
|
If this isn't the only query that needs information from Student and also Student_archive then it is maybe a good idea to create a view "Student_all" or so using the UNION query inside the view... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|