简体   繁体   中英

Matching company names in two tables

I have two tables with company names and their ids, the table Corporation_Name has ID and NAME , the other table DATA_Excel has CORPORATION as ID and C_Name as name ; I have to match company names in the data table with Corporation Name to make sure all the companies exist if not i only have to insert the company which is not present in Corporation name.

Currently i am using this query:

Select Distinct (B.corporation), B.C_name
from data_excel B, corporation_name A
where B.C_name <> A.name

also some times this is the case:

87  Société Générale de Belgique
87  Societe Generale de Belgique

Your query is not finding what you are looking for. You are all companies from A and matching them with all companies in B, meaning it will return a record for Societe Generale <> Fortis

Start with this:

    SELECT B.Corporation, B.C_Name
      FROM data_excel B
LEFT OUTER JOIN corporation_name A
        ON B.C_Name = A.Name
     WHERE A.Name IS NULL

This will still not solve everything, you will still have to replace

        ON B.C_Name = A.Name

With something like what John Doyle suggested, because Société will still not match Societe!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM