Forum Discussion
Dynamically Merging Different Tables - Sub querying
Hello, we have a django web application that is utilizing content types and generic foreign keys, and if you're unfamiliar with that, essentially. Its a referential lookup on other tables.
So in this example, I have merged together a few tables to represent this table structure, only showing relevant columns for complexities sake.
lookuptable (first row is formulas)
| formulas being applied | merged in from django_contenttype using utilized_model_id | merged in from django_contenttype using utilized_model_id | concat("public ", app_label, "_", model) | ||
| id | utilized_model_object_id | utilized_model_id | app_label | model | lookuptable |
| 1 | 4 | 112 | aqe | idarea | public aqe_idarea |
| 2 | 5 | 112 | aqe | idarea | public aqe_idarea |
| 3 | 6 | 112 | aqe | idarea | public aqe_idarea |
| 4 | 7 | 112 | aqe | idarea | public aqe_idarea |
| 5 | 8 | 112 | aqe | idarea | public aqe_idarea |
| 3691 | 1 | 354 | corelookup | lookupcheckoutsection | public corelookup_lookupcheckoutsection |
django_contenttype
| id | app_label | model |
| 1 | biq | area |
| 2 | biq | building |
| 112 | aqe | idarea |
| 354 | corelookup | lookupcheckoutsection |
aqe_idarea
| id | areaname | area rollup |
| 4 | TM north | transmissions |
| 5 | TM South | transmissions |
| 6 | TM north2 | transmissions |
| 7 | tm south2 | transmissions |
| 8 | TM south5 | transmissions |
What I want to do is merge into the lookuptable the dynamic lookup from the related django_contenttypes with a subquery.
The resulting table would look like lookuptable, but it would have aqe_idarea.areaname and aqe_idarea.area rollup on rows 1 - 5, but then it would do the lookup for corelookup_lookupcheckoutsection.[column N's name] on row 3691.
How do I do this in the advanced query editor to essentially sub query for each row?
1 Reply
- AlexisOlsonSuper User
I'm unsure that I'm understanding correctly. Can you explicitly show what the final result should look like for the given example?