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 🙂
>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