SLA
SLA

Reputation: 363

wrong mysql output

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

Upvotes: 0

Views: 70

Answers (3)

bot403
bot403

Reputation: 2162

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

Upvotes: 0

SubniC
SubniC

Reputation: 10317

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?

Upvotes: 0

Shakti Singh
Shakti Singh

Reputation: 86406

Change your query to

Select table1.value1, table2.value2, table1.AID1, table2.AID2

from table1,table2

where table1.FID = 1 AND table2.FID = 1

Upvotes: 1

Related Questions