I am trying to join five tables displaying the same information, but the table's data is sourced from different protocols.
I have created separate queries to recall fuel data and consumption rates and filtered them by using the join function to get Element names. (Thanks to the Dojo Q earlier last month.)
Now that I have created each query, I thought I would be able to overlay the tables into one big table and then possibly be able to apply a drop-down filter to narrow down the results.
I may be doing this all wrong, too and there may be a better or more efficient way of doing what I want.
Any help would be much appreciated.
What you are trying to achieve is a common use case, for which GQI currently has no baked in solution yet. Performing a join operation will make a table horizontally grow in size: we are adding more columns. But what you want to achieve is joining vertically. There is a way to do this, but I have to warn you, it is quite extensive to achieve:
- First of all, you will want those 5 tables to have an extra identifier column that contains a value that will not occur in the other tables. This can be as simple as a column that contains all 1's for table one, 2's for table 2, and so on.
In a query this translates to a column concat manipulation, where you can pick any column, and just type a value in the format. (1 for the first table, 2 for the second table, ...).
- Then we want to outer join each table sequentially, joined on that unique column we added in step 1. This will result in one huge table with all the columns and all the rows of the 5 tables. By design, because we performed an outer join, the columns from the other tables will contain nothing and we can use that to our advantage in our next step: merging.
- We need to merge all the info of the columns that represent the same info, together in a new column. This needs to be done for all columns.
This again can be achieved by a column concat manipulation, but now the columns that you select do matter, and the format needs to be {0}{1}{2}{3}{4} (in case you have 5 columns in each table).
- As a final step we can get rid of the initial columns and clean up the result. We will end up with a vertically joined table.
This is done with a simple select operator.
Be aware that I only illustrated this for vertically joining 2 tables that had 2 columns. The amount of effort scales linearly with the amount of tables you want to join. This is far from ideal and in the future there will probably be an alternative that is easier to set up, but for now this is the only way, I'm afraid.
Good luck.
Thanks Gilles. this looks awesome!
Of course it is never a 5min job.
I will give it a go and see how it turns out.