I have two tables. Table A contains ID, X, Y, Z. Table B contains ID, X, Y, Z, Job_number.
We recently added Job_number to table B. What I used before was a simple union query to get my resultset. (i.e.
select * from A
select * from B
Now that the fields are no longer the same I am unable to use union all. How can I write the query to link the tables in the following manner.
If table B contains an ID that equals the ID in Table A then show all the information for that record from Table B else if the ID does not exist in Table B then show all the information for the record from Table A.
Originally posted by r937
select B.ID, B.X, B.Y, B.Z, B.Job_Number
from TableA A
join TableB B
on A.ID = B.ID
select ID, X, Y, Z, null
where not exists
(select ID from TableB
where ID = TableA.ID )