SQL query to fetch data from 2 tables

280 views Asked by At

I have been trying to write a query where I have majority of information in one table and need information from just one column in the second table. Both table has a column that can be used as connection.

But unfortunately it does not give me the desired output. I am relatively new to coding and used PyPika to write my query. Can you please help?

It fives me "None" for "workflowtracker.COE" which I know there is data and many duplicate logs

Please find the query below

   q = Query.from_(workflowtracker).join(activitylog).on(
    activitylog.RequestId == workflowtracker.RequestId).select(workflowtracker.COE, activitylog.RequestId,
                                                               activitylog.SubjectLine,
                                                               activitylog.ResourceName, activitylog.ResourceEmail,
                                                               activitylog.GPN, activitylog.ExecutionDate,
                                                               activitylog.Status,
                                                               activitylog.TotalTimeTaken).where(
    (activitylog.Status == "In Progress") & (activitylog.ExecutionDate == excecutiondate))
1

There are 1 answers

3
Ganesh Gholap On

Please use this:

workflowtracker, activitylog = Tables('workflowtracker', 'activitylog')
q = Query
     .from_(workflowtracker)
     .join(activitylog)
     .on(workflowtracker.RequestId == activitylog.RequestId)
     .select(workflowtracker.COE, activitylog.RequestId,
               activitylog.SubjectLine,
               activitylog.ResourceName, activitylog.ResourceEmail,
               activitylog.GPN, activitylog.ExecutionDate,
               activitylog.Status,
               activitylog.TotalTimeTaken)
    .where(
    (activitylog.Status == 'In Progress') & (activitylog.ExecutionDate == excecutiondate)
    )