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

How to use Inner Join along with Where in MySQL?

I have 2 separate tables which are tuition and user. In the tuition table I have 2 fields named user_id and admin_id. I access related users by using Inner Join clause and user_id:

SELECT * FROM tuition t JOIN user u ON t.user_id = u.id

But in the tuition table, I want join only records in tuition which their admin_id is equal to 1. How should I rewrite the clause above? I wrote as this but didn’t show me anything:

SELECT * FROM tuition t JOIN user u ON t.user_id = u.id WHERE admin_id=1
SELECT * FROM tuition t WHERE admin_id=1 AND JOIN user u ON t.user_id = u.id

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

>Solution :

Where clause with inner join queries should be referenced with table name.

SELECT * FROM tuition t JOIN user u ON t.user_id = u.id WHERE table_name.admin_id=1
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