You can see the code is not very DRY. How can we improve this? I don’t think I can use extends because my from table is changing (it’s table_a first, then table_b). Since the joins are all left_outer I don’t have guarantees that all the records will be in tables x, y, and z, so I can’t start from these and use an extend…
I typically do something similar to what @IanT has suggested. The only difference is the common explore which contains the repeated code I’d name it something like _table_x_base and then also include the extension: required parameter in that base explore. In that base explore I’d also have the join condition for table_x use the foreign_key parameter instead of the sql_on parameter so it doesn’t require a reference to the explore which extends _table_x_base.
If you can’t use the foreign key parameter trick because your ids in the tables aren’t called id, you’ll need to not only include extends: [_table_x_base] in the table_a explore but then you’ll also need to explicitly state the table_x join again (not all the other tables that table_x joins to) and specify the sql_on parameter (just the following is enough)
This works because extends essentially copies the contents of the specified extended explore and then intelligently applies the code in the explore “on top”. For more details on how extends works this doc is really helpful and is the main way I DRY out my explore code. https://docs.looker.com/data-modeling/learning-lookml/extends