Skip to content
Advertisement

SQL join on two tables that are not related or have primary keys

I have the following query:-

Which results in something similar to this:-

I have another table (table 2) which contains values service and level_3_structure and also contains a column called ‘FTE’.

What I want to do, is join onto this table based on service and level_3_structure and return a sum of the FTE.

I have tried the below query, but it seems to duplicate table1 for each maching row, resulting in around 8.3 million results.

Advertisement

Answer

If your first query returns the rows you need, then you could join that (and not table1) to table2:

Still, it sounds like your table1 should have the column fte.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement