November 20th, 2012, 07:50 AM
Joining two tables?
I am facing some difficulties in joining two tables to display all my records. Here are the sample tables:
Name | year | late attendance
Andy | 2010 | 20
Andy | 2011 | 11
Jack | 2009 | 5
Name | year | early attendance
Andy | 2009 | 5
Andy | 2010 | 10
Joe | 2011 | 3
What I would like displayed is:
Name | year | late attendance | early attendance
Andy | 2009 | | 5
Andy | 2010 | 20 | 10
Andy | 2011 | 11 |
Jack | 2009 | 5 |
Joe | 2011 | | 3
I tried using the joins but I am not able to get it working properly..
Do hope someone can help point me to the right direction to get the display above. Thank you.
November 20th, 2012, 08:45 AM
Can you post the queries you have tried?
Any reason you have two tables?
November 20th, 2012, 08:55 AM
November 23rd, 2012, 09:06 AM
this is what you need in my case it is 2 tables #earlyAttendance and #lateAttendance
select ISNULL(e.name,l.Name) as name,
ISNULL(e.[year],l.[year]) as [year],
from #earlyAttendance e
full join #lateAttendance l