ankita sharma
ankita sharma

Reputation: 21

Match data values for two tables in Teradata Sql

Using Teradata :I have two tables with 10 records and 3 variables. All columns and values are same expect for three values in one variable. My task is to make code changes for table2 where both records are matched, by not hard coding any value. The second table was created by the first table , so there is no way to pick values by join etc .

Code :

    Create multiset table table2 as (
    Select * from table1 )
    With data primary index(var1);

Eg:

Var1 Var2 Var3
1 Abc 20
2 Cde 30
3 kgk 87
4 kjj 98
5 gvy 67
6 jbn 78
7 hvb 56
8 ihg 62
9 jhn 22
10 hbn 34
Var1 Var2 Var3
1 Abc 20
2 Cde 30
3 kgk 87
4 kjj 98
5 gvy 67
6 jbn 78
7 hvb 56
8 ihg 77
9 jhn 56
10 hbn 23

Upvotes: 0

Views: 599

Answers (1)

Popeye
Popeye

Reputation: 35920

Not sure what you want but you can find all the matching records using exists as follows:

select t.* from table2 t
  where exists 
       (select 1 from table1 tt
         where t.var1 = tt.var1 and t.var2 = tt.var2)

Upvotes: 0

Related Questions