I
I
IartanisI2019-06-17 15:49:29
SQL
IartanisI, 2019-06-17 15:49:29

How to find a match in a table?

There are two tables.
Table 1.
999991 Petro Petrovich Petreno
3323123 Vasily Vasilyevich Vasiliev
32321312 Evgeniy Evgenievich Evgenev
(this is one column)
Table 2.
Petro Petrovich Petr
Vasily Vasilyev Evgeniy
Evgeni
It is necessary to find matches for these parts in the tables. But in table 1, not all entries from the second. How to make a selection, and it would be ideal to just update the second one. Ie Petro Petrovich Peter => 999991 Petro Petrovich Petreno. I hope I wrote clearly

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Planet_93, 2019-06-17
@IartanisI

If you want to get records only those that are in both the first and second table, then use INNER JOIN.
Example

SELECT 
T2.Name,
T1.Name

FROM Table2 AS T2

INNER JOIN Table1 AS T1
ON T2.Name LIKE T1.Name

It would also be nice to remove spaces and and convert to common case at the time of comparison.
If you just need to update the values ​​from the second table, which partially matched from the first, then it's better to just use the Where clause on Update
UPDATE Table2 SET  Table2.Name = T1.Name

FROM Table2 AS T2, Table1 AS T1

WHERE T2.Name Like T1.Name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question