Given question I am not sure about overall setup and where this final query needs to be executed.
Since title of question has "dynamic" in it I am providing a solution using f strings which should allow most dynamic insertion.
Here is a way using f strings and pandas library for Big query.
import pandas as pd
from pandas.io import gbq
### create your final sql string to be executed to which you will append
final_sql_string = """
"""
tables = ['table_A', 'table_B', 'table_C', 'table_D']
for table in tables:
### if this is your last table in list no need for union
if table == tables[-1]:
### build out your query via f string
sql_string= f"""select col_A from `your_project.your_dataset.{table}`"""
### join via newline to your final sql query string
final_sql_string = "\n".join((final_sql_string, sql_string))
### if table is not last table then need to union
else:
sql_string= f"""select col_A from `your_project.your_dataset.{table}` union distinct """
final_sql_string = "\n".join((final_sql_string, sql_string))
### optional - check what your sql looks like
print(final_sql_string)
### submit to bq via pandas to get a pandas dataframe back
### on first try will ask to authorize against your project
pandas_dataframe_from_sql = gbq.read_gbq(final_sql_string,
project_id = 'your_project_id')
Sample of print statement from above
select col_A from `your_project.your_dataset.table_A` union distinct
select col_A from `your_project.your_dataset.table_B` union distinct
select col_A from `your_project.your_dataset.table_C` union distinct
select col_A from `your_project.your_dataset.table_D`
If you are executing via google cloud SDK you can insert this sql within as well.