0

Flag updation in table 2 for matching Records

There are two tables table1 and table2 and few matching records in both the tables table2 has to check the table1 records and match them, if any matching records found then table2 has to be updated with flag as matched ... could you please write a query for this

25th Dec 2019, 9:58 AM
Ranjith Purma
Ranjith Purma - avatar
2 Antworten
0
What are the characteristics of matching records? Can you describe your tables' structure? maybe it is needed in order to answer your question. OUTER JOIN is commonly used when looking for partial matches in two tables. I can't write the query right now, got no place to test the query validity anyways.
25th Dec 2019, 11:17 AM
Ipang
0
UPDATE table2 SET matched = 1 WHERE id IN (SELECT table2.id FROM table2 INNER JOIN table1 ON table2.data = table1.data); The query above works for tables table1 with columns id(int), data(anything) and table2 with columns id(int), data(anything), marked(tinyint). It will set value 1 for all rows in table2 that have the same value in column data as any row in table table1. Please, keep in mind that I am begginer in SQL and I couldn't test it, so it might not work, but I hope you got the point.😉
25th Dec 2019, 11:24 AM
Jan Štěch
Jan Štěch - avatar