I am working with a badly designed database and I ran into some problem.
I have two tables that I need to join on a ‘not unique ID’.
The software that currently works with the database sets a ‘0 value’ in the id if there is an error. This means if I try to join them a massive amount of records is joined on the 0 values.
Underneath an example of two tables and their not unique id fields i want to join them on
tbl1 tbl2
-----------
2 2
3 6
4 5
0 3
0 4
6 0
5 0
----------
What I want to achieve is this
tbl1 tbl2
-----------
2 2
3 3
4 4
0 * (no join)
0 * (no join)
6 6
5 5
----------
In other words, I don’t want the ‘0 values’ from tbl1 to join with all other ‘0 values’ from tbl2. I still want to have the record tbl1 without a join though.
Is this possible in 1 query?
extra information: SQL SERVER 2005 and there is no option to make the ID’s unique.
This should do the trick
this will give null values on the two that you put as *