Search code examples
sqlrdbms

use the redundant values in SQL


I have the following issue on SQL.

What I have (table A and table B)

enter image description here

What I want

enter image description here

My aim is to have a third table with the name of the file.

Info: my tables do not have any keys.

I've tried the code but it is not doing what I want

create table correspondance as 
   select b.var1, a.var1, a.var2 
   from A a 
   inner join B b on a.var1 = b.var2;

Any insights are welcomed.

Edited

I have this result :

var1       var2
azdt.csv   fich11.csv
zlata.csv  fich13.csv

Solution

  • You're just joining on the wrong fields, and too many fields selected

    select a.var1, b.var2 
       from A a 
       inner join B b on a.var2 = b.var1