0

I am working on 4 tables. The tables all hold data about routes (IE: From, To, Distance). Table1 may hold 5000 rows, Table2 has 2500 rows, Table3 has 3000 rows and Table4 has 3000 rows as well.

I have created INNER JOINs for all tables. This though, excludes data from Table1 as Table1.RouteId has an entry, but this data may not exist in Table2.

I need to compare all the data, and if Table1.RouteId is not in Table2, then it should just fill the columns of Table2 like "Not existing" or something like that so I can see that the data is missing in Table2, but does exist elsewhere.

How can I achieve this?

mnille
  • 1,328
  • 4
  • 16
  • 20

1 Answers1

-2
select * from A; 
select * from B; 
select * from C; 
select * from D; 

select * 
from A 
left join B on A.col1 = B.col1 
left join C on A.col1 = C.col1 
left join D on A.col1 = D.col1 
order by A.col1;

col1

1 
2 
3 
4 
5 

col1

2 
3 
4 

col1

1 
2 
3 

col1

3 
4 

col1  col1  col1  col1 

1     NULL  1     NULL 
2     2     2     NULL 
3     3     3     3 
4     4     NULL  4 
5     NULL  NULL  NULL 

Hope this helps!

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121
Raam
  • 63
  • 1
  • 8
  • 1
    It might help Raam if downvoters could post their reasons. I expect these will include poor formatting and a lack of descriptive comments. – David Rushton Mar 30 '16 at 09:53
  • I was wondering the same :( Truth is I don't have enough time to make it look pretty. – Raam Mar 30 '16 at 09:54
  • If you dont have time to write a proper answer, my advice is to not bother. – Jamiec Mar 30 '16 at 10:29