For simple lookups where you wish to look up a single value from another value you can use a MAPPING
load and then use the ApplyMap()
function. For example, say I have the following table:
LOAD
*
INLINE [
UserID, System
1, Windows
2, Linux
3, Windows
];
I have another table that contains UserID and UserName as follows:
LOAD
*
INLINE [
UserID, UserName
1, Alice
2, Bob
3, Carol
];
I can then combine the above tables with ApplyMap
as follows:
UserNameMap:
MAPPING LOAD
*
INLINE [
UserID, UserName
1, Alice
2, Bob
3, Carol
];
SystemData:
LOAD
UserID,
ApplyMap('UserNameMap', UserID, 'MISSING') as UserName,
System
INLINE [
UserID, System
1, Windows
2, Linux
3, Windows
];
ApplyMap is very fast and should not significantly slow down your load time (although it will not be as fast as a direct QVD load). However, as mentioned ApplyMap can only be used if you wish to map a single value into your table. For more fields, you will need to use a join
(which is similar to a SQL JOIN) if you wish to combine your results into a single table.
If you do not wish to join them into a single table (but keep it as a "star" scheme), just make sure that the fields that you wish to link are named the same. For example:
A_Left:
Load a_id_left,
a_name_left as [Name_Left]
inline [
a_id_left, a_name_left
1, 'nwsnd'
2, 'dcsdcws'
3, 'fsdf' ];
A_Rigtht:
Load a_id_right,
a_name_right as [Name_Right]
inline [
a_id_right, a_name_right
1, 'nwsnd'
2, 'dcsdcws'
3, 'fsdf' ];
Data:
Load id,
a_id_left,
a_id_right,
data
inline [
id, a_id_left, a_right_id, data
1, 1, 2, 37
1, 1, 3, 18
1, 2, 3, 62
];
(I have removed your "name" fields from "Data" as it would fail to load).
This will then work in your QlikView document due to QlikView's automatic field associativity.
However, if you wish to have the data in a single table (e.g. for output to QVD) then in your case you will need to JOIN
your two tables into Data
. We can rearrange some of the tables to make our life a bit easier, if we put your Data
table first, we can then join your other two tables on:
Data:
Load id,
a_id_left,
a_id_right,
data
inline [
id, a_id_left, a_id_right, data
1, 1, 2, 37
1, 1, 3, 18
1, 2, 3, 62
];
LEFT JOIN (Data)
Load a_id_left,
a_name_left as [Name_Left]
inline [
a_id_left, a_name_left
1, 'nwsnd'
2, 'dcsdcws'
3, 'fsdf' ];
LEFT JOIN (Data)
Load a_id_right,
a_name_right as [Name_Right]
inline [
a_id_right, a_name_right
1, 'nwsnd'
2, 'dcsdcws'
3, 'fsdf' ];
This will then resort in a single table named "Data" which you can then output to QVD etc.
You may wish to think about optimising your "Table A" extract since it is almost being loaded twice, this may take some time (e.g. from long distance server etc.) so it may be better to grab your data in one go and then slice it once it's in memory (much faster). A quick example could be like the below:
TableA:
LOAD
a_id_left,
a_id_right,
a_name_left,
a_name_right
FROM ...;
Data:
Load id,
a_id_left,
a_id_right,
data
inline [
id, a_id_left, a_id_right, data
1, 1, 2, 37
1, 1, 3, 18
1, 2, 3, 62
];
LEFT JOIN (Data)
LOAD DISTINCT
a_id_left,
a_name_left as [Name_Left]
RESIDENT TableA;
LEFT JOIN (Data)
LOAD DISTINCT
a_id_right,
a_name_right as [Name_Right]
RESIDENT TableA;
DROP TABLE TableA;