我在使用 Union 时遇到了查询问题。
我使用以下查询来获得我的结果:
SELECT substr(directory_vis,locate(":", directory_vis) +1, (locate(">>", directory_vis) - locate(":", directory_vis) -1)) as dossier, count(doc_id) as aantal_documenten
FROM openims_algemeen_document_data
WHERE 1=1
GROUP BY dossier
UNION
SELECT substr(directory_vis,locate(":", directory_vis) +1, (locate(">>", directory_vis) - locate(":", directory_vis) -1)) as dossier, count(doc_id) as aantal_documenten
FROM postin_document_data
WHERE 1=1
GROUP BY dossier
UNION
SELECT substr(directory_vis,locate(":", directory_vis) +1, (locate(">>", directory_vis) - locate(":", directory_vis) -1)) as dossier, count(doc_id) as aantal_documenten
FROM qualdoc_document_data
WHERE 1=1
GROUP BY dossier
ORDER BY dossier
我需要从多个表中获取所有“档案”。我在这里遇到的问题是我得到了重复的记录。因为同一个“档案”可以在多个表中。
我怎样才能解决这个问题?