Question

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
Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top