1

I have two tables, Table 1 with column email , number, enabled and Table 2 with column email,number. Now i have to compare the records of both the column from Table 1 and Table 2 , If the records matches in both the table then i have to update the column enabled as "Y" in table 1. Please help me with the query.

2 Answers 2

3

One way would be

UPDATE t1
SET    t1.enabled = 'Y'
FROM   Table1 t1
WHERE  EXISTS (SELECT *
               FROM   Table2 t2
               WHERE  t1.email = t2.email
                      AND t1.number = t2.number);

Or a more concise alternative

UPDATE Table1
SET    enabled = 'Y'
FROM   Table2
WHERE  Table1.email = Table2.email
       AND Table1.number = Table2.number;
0
UPDATE table_1 
SET table_1.fName = t2.FName, table_1.lName = t2.LName, table_1.status = "UPDATED" 
FROM table_1 AS t1 JOIN table_2 AS t2 USING (id) 
WHERE t1.fName!=t2.FName OR t1.lName!=t2.LName

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.