2017-09-19 4 views
1

は、クエリがどうなるかは、テーブルがSQL Serverでの反復値を持っている場合、内部結合を使用して抽出する方法を

table1 
|---------|------------|-------------|------| 
|object_id| object_name|parent_object|type | 
|---------|------------|-------------|------| 
|885  | unique1 |245   |UQ | 
|901  |unique2  |245   |UQ | 
|---------|------------|-------------|------| 

table2 
    |---------|------------|-------------| 
    |object_id| object_name|is_unique_constraint| 
    |---------|------------|-------------| 
    |245  | unique1 |1   | 
    |245  |unique2  |1   | 
    |---------|------------|-------------| 

出力

|---------|------------|-------------|-------|-------------------| 
|object_id| object_name|parent_object|type |isuniqueconstraint | 
|---------|------------|-------------|-------|-------------------| 
|885  | unique1 |245   |UQ  |1     | 
|901  |unique2  |245   |UQ  |1     | 
|---------|------------|-------------|-------|-------------------| 

必須私のクエリを書きながら、私は取得しています繰り返しの結果

答えて

2

私はちょうどobject_namejoin条件:

select . . . 
from table1 inner join 
    table2 
    on table1.parent_object_id = table2.object_id and 
     table1.object_name = table2.object_name 
where type = 'UQ' and is_unique_constraint = 1; 
+0

ありがとうございました – user3756799

関連する問題