0

I am in Python and I have the above 2 queries which I want to join them in 1.

def fly_away(session, line_id):
    query = session.\
              query(
                Pilot.Id,
                Pilot.EntityId,
                Pilot.From
              ).\
    filter(Pilot.Id == line_id)

    query = session.\
                  query(
                    CTower.Id,
                    CTower.Time,
                    CTower.Associate
                  ).\
    filter(CTower.Associate == line_id)

I tried to use join but I dont know how to use it correctly. Can I have some help please?

2
  • The query makes no sense to me. Please, show us how the data looks like and what are you trying to get from it. Commented Mar 9, 2015 at 9:08
  • The queries in my question are 2. I want to join them. I want to get data from two different tables .. with one query.. the data and the tables are written on my question. Commented Mar 9, 2015 at 9:12

2 Answers 2

1

I don't know what database are you using and what driver are you using to connect python to the database but I will post the sql query that will do the job. I am sure, you can use it with your driver.

SELECT Pilot.Id, Pilot.EntityId, Pilot.From, CTower.Id, CTower.Time, CTower.Associate 
FROM Pilot, CTower 
WHERE CTower.Associate == Pilot.Id
Sign up to request clarification or add additional context in comments.

3 Comments

@TakisMakis What is session object?
its something irrelevent on how to join these two queries.
@TakisMakis Well, I have joined those two queries as you can see from my answer, if that is what you want. If you want to run it in python, you should give more info about stuff you use.
0
def fly_away(session, line_id):
  query = session.\
          query(
            Pilot.Id,
            Pilot.EntityId,
            Pilot.From,
          ).\
          outerjoin(CTower, Pilot.Id == CTower.Associate).\
          filter(Pilot.Id == line_id)     
  return query

this is what I am trying now.. and its working .. but not exactly as I want

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.