Click here to Skip to main content
15,614,439 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have two tables and I have to compare the tables data and if data matches that assign the value "Yes" to the column status and if unmatched then assign the value "No" to that status column and i have to do this for multiple values. I need to do this using PHP and display the data in PHP table with the matched value status and unmatched value status.

Thanks in advance.

What I have tried:

I have tried sql query and able to fetch the unmatched values in table but not able to assign the status to matched and unmatched values.
Updated 16-Apr-21 3:20am

I think you'll find MySQL: INTERSECT Operator[^] most helpful.

Run each table UPDATE against the other table to set 'Yes' and 'No' with simple "IN" and "NOT IN".

Share this answer
You can write a query like this one:

$sql = "UPDATE table1 t1
JOIN table2 t2
ON =

SET t1.status = "YES" ";

This should work well
Share this answer
CHill60 28-Jun-19 5:23am    
It will work well for the update but does not satisfy the requirement "display the data in PHP table with the matched value status and unmatched value status"
Can you please help me out with the proper query? I need to apply 'Yes' or 'No' against each of the values in the php table.
Share this answer
Richard Deeming 10-May-18 12:49pm    
If you want to reply to a solution, click the "Have a Question or Comment?" button under that solution.

DO NOT post your reply as a new "solution".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900