I need to do a join on two tables, I need EVERYTHING from table A, and just the stuff from table B where the ‘REF’ for each row, is not already in table A’s results.
Key Facts:
Table B contains the complete amount of ID’s/Names however all the other information is blank. Its basically just a table with all employee’s name’s and id’s but its a complete list.
Table A contains a limited amount of results but all the other columns have data in them.
What I need is to use Table B as a complete reference rather than just see what exists in table A so basically:
“Show me everything from table A, and add the extra people’s details
found in table B where they dont already exist in table A to give me a complete result set”
select
ID,
Name,
StartDate,
EndDate,
State,
Status,
Comment,
IsComment
from
tableA
select
ID,
Name,
StartDate,
EndDate,
State,
Status,
Comment,
IsComment
from
tableB
Table A contents:
ID Name START_DATE END_DATE STATE Status Comment Is_Comment
6760 chris 2012-09-03 2012-09-09 4 Applied 0
6524 dave 2012-09-03 2012-09-09 4 Applied 0
4268 james 2012-09-03 2012-09-09 4 Applied Friday-Off 1
7851 rob 2012-09-03 2012-09-09 4 Applied 0
Table B contents
ID Name START_DATE END_DATE STATE Status Comment Is_Comment
6760 Chris
6524 dave
4268 james
7851 rob
4521 ryan
5698 julie
4596 rory
1111 mary
5621 owain
9999 jacob
After the join what I want to see:
ID Name START_DATE END_DATE STATE Status Comment Is_Comment
6760 chris 2012-09-03 2012-09-09 4 Applied 0
6524 dave 2012-09-03 2012-09-09 4 Applied 0
4268 james 2012-09-03 2012-09-09 4 Applied Friday-Off 1
7851 rob 2012-09-03 2012-09-09 4 Applied 0
4521 ryan
5698 julie
4596 rory
1111 mary
5621 owain
9999 jacob
Use a Left join