Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get data from 3 tables using single query

I have 3 tables in a MySQL database

user

user_id, (PK)
email

agreement_user

agreement_user_id, (PK)
user_id, (FK user.user_id)
details

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

contract

contract_id, (PK)
agreement_user_id, (FK agreement_user.agreement_user_id)

details

What should be the query to get contract.details and user.email given a contract_id

>Solution :

maybe you can try

SELECT contract.details, user.email FROM contract
INNER JOIN agreement_user ON contract.agreement_user_id = agreement_user.agreement_user_id
INNER JOIN user ON agreement_user.user_id = user.user_id
WHERE contract.contract_id = @yourSpecificId;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading