if I have these two tables :
Table1
AID1____________FID____________value1
1------------1----------12
7------------2-----------1
8------------1-----------1
Table2
AID2____________FID____________value2
7------------1----------3.3
When I execute the following query :
Select table1.value1, table2.value2, table1.AID1, table2.AID2
from table1,table2
where table1.FID = 1 or table2.FID = 1
I get :
value1_____________Value2_____AID1______AID2
开发者_如何学运维12----------------- 3.3--------1--------7
1------------------3.3---------7--------7
1------------------3.3---------8---------7
But this is not the desired output, because some values should be NULL, but what I get is values doubled ! Can anyone help ?
This is my desired output : value1______Value2_AID1___AID2
12----------------- 3.3--------1--------7
1------------------NULL---------7--------NULL
1------------------NULL---------8---------NULL
Change your query to
Select table1.value1, table2.value2, table1.AID1, table2.AID2
from table1,table2
where table1.FID = 1 AND table2.FID = 1
I've tried the scenario you describe and it is working as expected.
Table1:
AID1 -> int
FID -> int
value1 -> float
Table2:
AID2 -> int
FID -> int
value2 -> float
result:
value1, value2, AID1, AID2
12,3.3,1,7
1,3.3,7,7
1,3.3,8,7
NULL,3.3,NULL,7
How are you running it?
I think you want a union.
Select table1.value1, table1.AID1, from table1 where table1.FID = 1
union
Select table2.value2, table2.AID2 from table2 where table2.FID = 1
精彩评论