I have three tables admin, doctor, manager and they have no values that are common in them and each of them has an email column but since emails are unique there are no common values.
I want to write a query in SQLAlchemy which joins three tables and then I can filter the three virtual email column based on the email provided by the user.
Table admin
- id (unique)
- email (unique)
- name (unique)
Table doctor
- id (unique)
- email (unique)
- doctorName (unique)
Table manager
- id (unique)
- email (unique)
- managerName (unique)
def get_role_by_user_email(email):
query = session.query(admin,
doctor,
manager
)\
.filter(admin.email == email)\
.filter(doctor.email == email)\
.filter(manager.email == email)\
.first()\
I am hoping the query will result in a unique row from three tables.
JOIN is not working as there are no common records in terms of ids and emails between these three tables.
In SQL terms this is what I am trying to achieve
results = admin table where admin.email == user_provided_email or doctor table where doctor.email == user_provided_email or manager table where manager.email == user_provided_email
results object will contain only one row.
Thanks