-1

table1 と table2 の 2 つのテーブルがあります
。例: table 1

id1     name1    fatherName1    village1    category1    subcategory1  
1,        a,       x1,          v1,          c1,           sc1   
2,        b,       x2,          v2,          c2,           sc2   
3,        a,       x1,          v1,          c3,           sc3  
4,        c,       x4,          v4,          c4,            sc4 

テーブル2

id2     name2   fatherName2  village2  category2   subcategory2  
1,        a,      x1,            v1,        c5,        sc5   
2,        b,      x2,            v2,        c2,        sc2  
3,        c,      x5,            v5,        c3,        sc3  
4,        d,      x6,           v6,         c6,        sc6  

上記で、テーブルの 6 列と 4 行について説明しました。
今、私は必要です

all the rows table1 and table2 where 
(table1.name1=table2.name2 
and table1.fatherName1= table2.fateherName2 
and table1.village1=table2.village2) 
OR (table1.name1=table1.name1 
and table1.fatherName1= table1.fateherName1 
and table1.village1=table1.village1) 

好きな方で、java または sql のいずれかで答えることができます。みんな私を助けてください....事前に感謝します。

4

4 に答える 4

0

私はあなたの質問を見て、なぜあなたが質問するのか疑問に思います。なぜなら、あなたは自分で答えを定式化しているからです (少なくともその where 句)。

select *
from   table1, table2
where (table1.name1=table2.name2 
and table1.fatherName1 = table2.fatherName2
and table1.village1=table2.village2
) OR 
(table1.name1=table1.name1 
and table1.fatherName1= table1.fatherName1 
and table1.village1=table1.village1)
于 2013-09-09T08:18:35.510 に答える
0

「union」と「distinct」を使用して、やりたいことを実行できると思います:)

于 2013-09-09T08:14:56.657 に答える
0

これを参照してください。それに加えて、部分的な回答を提供します。クエリは次のようにする必要があります。

Query = "Select * from table1 t1,table2 t2 where (YOUR CONDITION COMES HERE)"
于 2013-09-09T08:16:45.927 に答える
0
      (select t1.id1 as id,t1.name1 as name from table1 t1 inner join t2 on (t1.name1=t2.name2 and t1.fatherName1=t2.fatherName2 and t1.village1=t2.village2))
        union all
      (select t2.id2 as id,t2.name2 as name from table2 t2 inner join t1 on (t1.name1=t2.name2 and t1.fatherName1=t2.fatherName2 and t1.village1=t2.village2))
于 2013-09-09T08:21:34.177 に答える