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

MySQL Left Join use IN to compare only values present in which second table should give only those values which are present in first table

How can I write a MySQL query using LEFT JOIN and IN to compare values between two tables, where the second table should only provide values that are present in the first table?

I need to ensure that the query retrieves only the matching values between the two tables.

PS: I request you to pls revert back whatever your thoughts are instead of giving votes as it would help me next time 🙂

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 :

You can try using the below query:

SELECT t1.column1, t1.column2, t2.column3 FROM table1 t1 LEFT JOIN table2 t2 ON t1.column1 = t2.column1 AND t2.column1 IN (SELECT column1 FROM table1);

As mentioned in comment it would be better if you could post some sample data or your output to have better understanding

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