Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Relationship between two tables (many to one value)

Hello everybody,

i have the following question. I have a table witch contains Employee data like Number, Name and Function.

Also i have a Table that contains the Function characteristic. Here are the example:

FunctionTable:

function_nrfunction
1Employee
2management
3trainer
4trainee

Employee Table:

emp_nrfunction_nrlastnamename
11##4SmithJohn
21##3##2ColleTim
31##MeierTina

Now my question is, how i can link them together so that every function number in the Employee Table would pick all the functions?

Thank you for help.

Have a nice day.

1 Solution

Accepted Solutions
lironbaram
Partner - Master III
Partner - Master III

you can do this by separating the employee table to two tables

your script will look something like

Employee:

load emp_nr, lastname ,nane

from EmployeeTable ;

Employee_function:

load emp_nr,

       subfield(function_nr,'##') as function_nr

From EmployeeTable;

FunctionTable:

load * From functionTable;

View solution in original post

5 Replies
lironbaram
Partner - Master III
Partner - Master III

you can do this by separating the employee table to two tables

your script will look something like

Employee:

load emp_nr, lastname ,nane

from EmployeeTable ;

Employee_function:

load emp_nr,

       subfield(function_nr,'##') as function_nr

From EmployeeTable;

FunctionTable:

load * From functionTable;

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Like this:

LinkTable:

LOAD emp_nr, subfield(function_nr, '##') AS function_nr

RESIDENT Employee_Table;

DROP Field function_nr FROM  Employee_Table;

Add this to your script after loading Employee_Table.

The two-parameter version of SubField() will create a link record for every value in function_nr.

Colin-Albert
Partner - Champion
Partner - Champion

You can use a mapping load to get the function name and then use subfield to appy the maping to the Employees table.

Function_Map:

mapping load

     function_nr,

    function

from [function data table]

;

Employees:

load

     emp_nr,

      applymap('Function_Map', subfield(function_nr, '##')) as function,

     lastname,

     name

from [employee data table]

kiranmanoharrode
Creator III
Creator III

Hi Tigetlily,

Use subfield() function  for Employee Table,

Employee:

Load emp_nr,

         Subfield(function_nr,'##')  as function_nr,

         lastname,

         name

From employee.qvd;

You will get below output for above script;

emp_nrfunction_nrlastnamename
11SmithJohn
14SmithJohn
2

1

ColleTim
23ColleTim
22ColleTim
31MeierTine
Not applicable
Author

Hello,

thank you all for the answer. Now it works and i'm so happy 😉