Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

More than one field as a join to another table

Hi,

I have a predicament where I need to link two tables together but there are two potential fields in one table that I would like to join to the other.

Take the data below for example:

Orders:

Order NumberSalesPerson1SalesPerson2
12345123456
98765456

Employees:

EmpNoEmpName
123Bob Smith
456John Jones

So for an order there could be 2 (potentially more) sales people working on it. What I want to do is join the Orders table and the Employees table, so that I can select an employee name and see what orders they have worked on. If there was only a single field in the orders table then it would be easy, but a record needs to be returned in the employee appears in either field.

Is it possible to get this to work without duplicating the number of records in the orders table (to make it one row per order/employee)?

Thanks

1 Solution

Accepted Solutions
RedSky001
Partner - Creator III
Partner - Creator III

I'd do it as follows.  Yes the order Id is duplicating in the SalesPerson table but I'd rather have the duplicaiton happening in a dimension table than the fact table.

Temp:

load * Inline [ Order Number, SalesPerson1, SalesPerson2

  12345, 123, 456

  98765, 456,

  ];

EmpTable:

load * Inline [EmpNo, EmpName

  123, Bob Smith

  456, John Jones

  ];

DimSalesPerson:

load [Order Number], SalesPerson1 as _Key_EmpID Resident Temp; !

Concatenate (SalesPerson)

load [Order Number], SalesPerson2 as _Key_EmpID Resident Temp;

Inner join (SalesPerson)

load  EmpNo as _Key_EmpID, EmpName as SalesPersonName Resident  EmpTable;

FactOrders:

load [Order Number] Resident Temp;

drop Table EmpTable;

drop Table Temp;

View solution in original post

6 Replies
gandalfgray
Specialist II
Specialist II

You can do something like this:

Left Join (Orders)

load EmpNo As SalesPerson1,

     EmpName As SalesPersonName1

resident Employees;

Left Join (Orders)

load EmpNo As SalesPerson2,

     EmpName As SalesPersonName2

resident Employees;

drop table Employees;

swuehl
MVP
MVP

I think it would be best to create a table that shows a record for every relation of Order number to EmpNo (i.e. the solution you excluded in your last paragraph).

If you just don't want to duplicate order lines with other fields, you can create a separate table only containing Order number and EmpNo, that links between Orders table and Employees table.

awhitfield
Partner - Champion
Partner - Champion

Hi James,

the simplest way would be one line per order / sales person, as attached

HTH Andy

pratap6699
Creator
Creator

orderstbl:

Load orderno,

salesperson1,

salwsperson2

from ---------.xlsx;

LEFT JOIN

Load salesperson1 as emp

,resident orderstbl

LEFT JOIN

Load salesperson1 as emp

,resident orderstbl

employtbl:

Load emp,

ename

from ----path;

RedSky001
Partner - Creator III
Partner - Creator III

I'd do it as follows.  Yes the order Id is duplicating in the SalesPerson table but I'd rather have the duplicaiton happening in a dimension table than the fact table.

Temp:

load * Inline [ Order Number, SalesPerson1, SalesPerson2

  12345, 123, 456

  98765, 456,

  ];

EmpTable:

load * Inline [EmpNo, EmpName

  123, Bob Smith

  456, John Jones

  ];

DimSalesPerson:

load [Order Number], SalesPerson1 as _Key_EmpID Resident Temp; !

Concatenate (SalesPerson)

load [Order Number], SalesPerson2 as _Key_EmpID Resident Temp;

Inner join (SalesPerson)

load  EmpNo as _Key_EmpID, EmpName as SalesPersonName Resident  EmpTable;

FactOrders:

load [Order Number] Resident Temp;

drop Table EmpTable;

drop Table Temp;

pratap6699
Creator
Creator

great