0

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
5
  • you forgot to join the tables Commented Dec 16, 2010 at 15:02
  • The result set is not clear. Explain what result should be retrieved. Commented Dec 16, 2010 at 15:08
  • for example, why is 3.3 displayed three times, can't I have it just once ( in the first row only) , and in all the other rows set to NULL ? its because I only have it once in Table2 Commented Dec 16, 2010 at 15:10
  • Well what IS the output you expect? Do you want a JOIN, an OUTER JOIN, a UNION? Commented Dec 16, 2010 at 15:13
  • what im saying is that I dnt want entries t be repeated , could this be possible ? Commented Dec 16, 2010 at 15:17

3 Answers 3

1

Change your query to

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

from table1,table2

where table1.FID = 1 AND table2.FID = 1
Sign up to request clarification or add additional context in comments.

1 Comment

This will give cartesian production, not what the OP expected.
0

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?

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.