我正在尝试在Drupal网站上选择重复的节点,基本上,我需要选择具有相同“ tnid”(翻译节点ID)并共享相同“语言”的节点。

但是我不知道如何编写查询,我想我做了第一部分,找到了具有通用tnid的节点,就像这样

SELECT origin.nid, origin.tnid, origin.title, origin.language
FROM node AS origin
JOIN (select nid, tnid from node
      group by tnid having count(tnid) > 1) common_tnid ON common_tnid.tnid = origin.tnid
#JOIN node common_lang ON common_lang.language = origin.language
                      AND common_lang.tnid = origin.tnid
WHERE origin.tnid != 0


考虑到语言部分是我最大的障碍,我如何将其添加到查询中?因此,我尝试了很多东西。评论。

最佳答案

尝试这个:

SELECT
  table1.nid nid,
  table1.tnid tnid,
  table1.language language,
  table1.title title
FROM
  (
    SELECT *
    FROM
      table1
    GROUP BY
      tnid, language
    HAVING
      COUNT(*) > 1
  ) dupe
  LEFT JOIN
  table1
    ON dupe.tnid = table1.tnid
       AND dupe.language = table1.language


SQL提琴:http://sqlfiddle.com/#!9/294cc/1/0

关于mysql - 查找具有共同属性的重复项,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29793927/

10-11 09:05