views:

38

answers:

1

you have this 2 tables:

table1
-------------
id
fromId
fromOtherTableId
person

and

Table2
-------------
OtherTableId    
Person


first question

this query work fine

select t.id
from table1 as t inner join Table2 as a on t.fromOtherTableId=a.OtherTableId    
where a.Person = 54
union
select t1.id
from table1 as t1 inner join Table1 as t2 on t1.fromId=t2.fromId
where t2.Person = 54

how to remove the union so the query would still be working?


second question

how would you manage the fact that you cannot create an entry in table1 where table2.fromothertableid(person) would be put into table1.person(circular thing)

same with the fact that you cannot create an entry in table1 where table1.fromid(person) would be put into table1.person(circular thing)

this would be good:

table1
---------------
1, null, 1 , 100
2, 1, null , 200

table2
--------------
1, 200

this wouldn't be good(between **)

table1
---------------
1, null, 1 , 100
2, 1, null , 200
**3, 1, null , 100**
**4, null, 1, 200**

table2
--------------
1, 200
A: 

Question 1:

select t.id
from table1 as t 
   join Table1 as a on a.fromId = t.fromId
   join Table2 as o on o.otherTableId = t.fromOtherTableId
where  54 In (a.Person, o.person)

Queston 2: I have many questions about this schema... on the surface it does not seem right, but I don't know what business model it attempts to represent... Can you elaborate ?

Charles Bretana
Fredou