Download PDF
Download page Merging/JOINing tables with SQL.
Merging/JOINing tables with SQL
Merging tables by partial match
Use case:
You need to look up tables by partial match.
Solution:
Switch the page to the edit mode.
Insert the Table Transformer macro and paste the table or the macros outputting tables within the macro body.
Select the macro and click Edit.
In the Presets tab select Custom transformation and click Next.
Enter the following SQL query:
SELECT * FROM T1 LEFT JOIN T2 ON T1.'Codes'->split("KR")->indexOf(REPLACE(T2.'Code', "KR", ""))>-1
SQLClick Next.
Save the macro and the page.
Merging tables using SQL filtration
Use case:
You have two tables where the columns differ.
You need to merge two tables where the entrys meet the conditions:
- transaction date in Table 1: October 2018
- customer type in Table 2: business
Solution:
- Switch the page to the edit mode.
- Insert the Table Transformer macro and paste the tables or the macros outputting tables within the macro body.
- Select the macro and click Edit.
- In the Presets tab select Custom transformation and click Next.
Enter the following SQL query:
SELECT * FROM T1 JOIN T2 ON T1.'Transaction ID' = T2.'Transaction ID' WHERE ( 'Transaction Date' >= "10 / 1 / 2018" AND 'Transaction Date' < "11 / 1 / 2018" ) AND ( 'Customer Type' = "Business" )
SQLWHERE ('...' >= "10/1/2018" AND '...' < "11/1/2018") AND ('...' = "...") extracts only those records that fulfill a specified condition.
- Click Next.
- Define the table settings and view options if needed.
- Save the macro and the page.
You can use FORMATWIKI function for the purposes of cell formatting.
Automatic filling blanks and updating values in tables
Use case:
ou have two tables containing information about employees on different pages.
The first table is an Excel spreadsheet with data.
You need to fill in the blanks or update values in the second table with data from the first one by matching the 'Employee' columns.
Solution:
- Switch the page to the edit mode.
- Insert the Table Transformer macro and paste the tables or the macros outputting tables within the macro body.
- Select the macro and click Edit.
- In the Presets tab select Custom transformation and click Next.
Enter the following SQL query:
SELECT T1.'Number', T1.'Employee', T1.'Position', CASE WHEN T2.'City' IS NULL THEN T1.'Location' ELSE T2.'City' END AS 'Location' FROM T1 LEFT JOIN T2 ON T1.'Employee'->toLowerCase() = T2.'Employee'→toLowerCase()
SQLClick Next
- Save the macro and the page.
You can use FORMATWIKI function for the purposes of cell formatting.
Advanced use case:
You need to select values manually (without column matching) and add them into empty cells only.
Solution:
Enter the following SQL query:
SELECT T1.'Number',T1.'Employee',T1.'Position',
CASE
WHEN T1.'Employee' = "John Anderson" AND T1.'Location' IS NULL
THEN (SELECT T2.'City' FROM T2 WHERE T2.'Employee' = "John Anderson")
WHEN T1.'Employee' = "Alban Jacobs" AND T1.'Location' IS NULL
THEN (SELECT T2.'City' FROM T2 WHERE T2.'Employee' = "Alban Jacobs")
ELSE T1.'Location'
END
AS 'Location'
FROM T1