Benny Benny - 7 months ago 15
SQL Question

Compare two columns for difference mark the difference in mysql

Need to compare two fields and mark the similar fields in third table.

For Example:

Tables

**customer:
phone id,
phonenumber
followstatus

received_Customer:
rc_id,
rc_phonenumber.**


I need to mark the fdnumber with f or n/a in follow up which is in received and customer table.

Update customer table :
select b.phonenumber from received_customer n join customer b on b.phonenumber = n.phonenumber SET followUpStatus= 'y' ;

SQL Query needed.

Answer

Try this:

SELECT c.phone_id, c.phonenumber, 
      (CASE WHEN f.fdnumber IS NULL THEN 'n/a' ELSE 'f' END) followUpStatus
FROM customer c 
INNER JOIN received_Customer rc on c.phonenumber = rc.rc_phonenumber 
LEFT OUTER JOIN follow_up f on c.phonenumber = f.fdnumber;

EDIT

For update table data:

UPDATE customer c 
LEFT OUTER JOIN received_Customer rc on c.phonenumber = rc.phonenumber
SET c.followUpStatus = (CASE WHEN rc.rc_phonenumber IS NULL THEN 'n' ELSE 'y' END)
Comments