MySQL修剪(concat ...)

时间:2013-12-06 05:43:36

标签: mysql sql select subquery notin

此查询有什么问题?

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); 

目标是仅提取不存在的Source,Source_Description和URL组合的记录(在我的情况下也是如此)。但是,如果它只在一列中看到匹配,则忽略它。

MySQL新手......如果有更好的方法来进行此查询,我将不胜感激。

1 个答案:

答案 0 :(得分:2)

试试这个:

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);

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