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

im trying to find out unmatched records from 2 tables i had tried below query it works fine but i need to find for multiple column matching plz help

res = mysql_query("SELECT * FROM emp WHERE emp.roll_no NOT IN (SELECT emp_no FROM emp_old)");

similarly i had did as follows..
it has error..

emp has rollno and name

emp_old has emp_no and name

i need to find out for this two columns which are unmatched

res = mysql_query("SELECT * FROM emp WHERE emp.roll_no AND emp.name NOT IN (SELECT emp_no AND name FROM emp_old)");
Posted

1 solution

Hello, try these ones
1.
SQL
SELECT *
  FROM emp
 WHERE NOT EXISTS (SELECT emp_old.roll_no, emp_old.name
                     FROM emp_old
                    WHERE emp_old.roll_no = emp.roll_no AND
                          emp_old.name = emp.name)

2.
SQL
SELECT emp.*
  FROM emp
  LEFT JOIN emp_old
    ON emp_old.roll_no = emp.roll_no AND
       emp_old.name = emp.name
 WHERE emp.name IS NULL
 
Share this answer
 
v2
Comments
Arun-23 23-Jan-14 2:20am    
its working its listing out unmatched list of 2 columns emp_no & name i want to highlight this two columns according to result is this possible..
skydger 23-Jan-14 14:00pm    
Where do you wish to highlight these columns?
Arun-23 23-Jan-14 23:44pm    
in fetched result
while($row=mysql_fetch_array($res))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row['roll_no'] . "</td>";// which rollno is wrong in red color
echo "<td align='left' width='200'>" . $row['name'] . "</td>";//which name is wrong in blue color
echo "</tr>";
}

echo "</table>";
skydger 24-Jan-14 2:01am    
Consider to use for html 4.0 or to use CSS. Please refer following link for details: http://www.w3schools.com/tags/att_font_color.asp

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