Home > Back-end >  How to find matching values in two different tables SQL
How to find matching values in two different tables SQL

Time:10-28

I am trying to write a statement to find matching values from two different tables and set table 1 suppression to 1 if person_id from table 2 matches person_id from table 1 in SQL.

Table 1 = id_num, person_id, phone_number, supression

table 2 = person_id, uid

So if person_id from table 2 matches person_id from table 1 it should set each record to 1 in suppression column in table 1.

CodePudding user response:

Sample data and dbms would be needed to give a reliable answer, but the general gist is like this

-- for mySql, syntax will vary by dbms
update table1 
 inner 
  join table2
    on table1.personid = table2.personid
   set table1.suppression = 1;

http://sqlfiddle.com/#!9/42dbf6

CodePudding user response:

Thank you for the first suggestion. I ended up going with the below

update in_12768_load1_all set "suppression" = '1' from (select * from "sup1027") as a where a."person_id" = in_12768_load1_all."person_id";

I thought I explained my question pretty well. No clue why someone would down arrow this.

  • Related