Do you want to programmatically use tab_a to get data from tab_b? You can use python. Use a python connector to connect to your db to fire queries. Write code to create a .sql file which creates the sql by using data from tab_a. Write the sql query generated to another .sql file and then fire sql command in the second file using the python connector. Store this data into a pandas dataframe and then this df can either be written back to the DB or file or sent over email as you see fit.