MySQL trim(concat ...)

590 views Asked by At

What is wrong with this query?

SELECT DISTINCT source, 
                source_description, 
                url 
FROM   staging_census 
WHERE  Trim(Concat(source, source_description, url)) NOT IN (SELECT 
       Trim(Concat(source, 
source_description, url)) 
                                                             FROM   dim_source); 

The objective is to pull only the records where a combination of Source, Source_Description and URL that does not exist (which is true in my case). However, if it sees a match in only one column it ignores it.

MySQL Newbie... if there is a better way for this query I would appreciate it.

1

There are 1 answers

0
Saharsh Shah On

Try this:

SELECT DISTINCT Source, Source_Description, URL
FROM Staging_Census
WHERE CONCAT(TRIM(Source), TRIM(Source_Description0, TRIM(URL))) NOT IN (SELECT CONCAT(TRIM(Source), TRIM(Source_Description0, TRIM(URL))) FROM DIM_Source);

OR

SELECT DISTINCT SC.Source, SC.Source_Description, SC.URL
FROM Staging_Censusc SC 
LEFT JOIN DIM_Source DS ON (TRIM(SC.Source), TRIM(AC.Source_Description0, TRIM(SC.URL)) = (TRIM(DS.Source), TRIM(DS.Source_Description0, TRIM(DS.URL))
WHERE DS.DimsourceId IS NULL