x******l 发帖数: 39 | 1 I have a table a
ID | Name | City
1 |Jack | Null
2 |Tom | Null
And table b
ID | Name | City
1 |Jack | Dever
2 |Tom | Dallas
I need to write a query to join these two tables by id, name and city if
they are not null in table a. But any of these three column could be null
for each row.
I wrote one below but the performance is bad when data grows
Select * from a, b
Where (a.id is not null and a.id=b.id or a.id is null) and
(a.name is not null and a.name=b.name or a.name is null) and
(a.city is not null and a.city=b.city or a.city is null)
Basically, I need to join on the column when it is not null in table a.
Could you shed some light on this?
Thanks a lot! |
|