'How to use output of one query into another query in python/ sql?
I have one query which is like:
q = f"""
select distinct
s.user_id
,d.prime_tagging_by_issuer_and_product
from sms_callback_events s
inner join {table} d
on s.user_id = d.user_id
where event_name = 'event_1'
and d.user_id is not null and d.user_id != ''
"""
with redshift_direct() as conn:
sms_df = pd.read_sql(q, conn)
Now I want to discard only those user_ids which were selected in this query and pass rest of the user Id's to my another query which is also similar
q = f"""
select distinct
s.user_id
,d.prime_tagging_by_issuer_and_product
from flash_events s
inner join {table} d
on s.user_id = d.user_id
where event_name = 'event_1'
and d.user_id is not null and d.user_id != ''
"""
with redshift_direct() as conn:
flash_df = pd.read_sql(q, conn)
here {table} is nothing but a dataframe of user_ids and plus some other columns.
How do I achieve this? How do I put a condition where I dont pass the user ids from sms_df to my next query?
Any help is appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
