Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

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
question from:https://stackoverflow.com/questions/65845217/match-data-values-for-two-tables-in-teradata-sql

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...