具有多联合的重复条目

发布于 2024-12-03 06:52:57 字数 1802 浏览 2 评论 0原文

我有这个

               (SELECT  DISTINCT '1' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana da'    AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '2' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'da silva dias'  AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '3' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana'       AND sobrenome      REGEXP 'da silva dias'   AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '4' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana da'    AND sobrenome      REGEXP 'silva dias'      AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '5' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'silva dias'     AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '6' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana'       AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '7' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana'       AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '8' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'leidiana'       AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '9' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'leidiana da'    AND tipo <> '7')   ORDER BY sb

结果:

2 - leidiana da silva dias 3 - 莱迪安娜·达席尔瓦·迪亚斯 4 - 莱迪安娜·达席尔瓦·迪亚斯 5 - 莱迪安娜·达席尔瓦·迪亚斯 6 - leidiana da silva dias

7 - leidiana da silva dias

正如你所看到的,我试图解决这个问题,最终把所有的东西都变成了不同的。 RS

I have this

               (SELECT  DISTINCT '1' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana da'    AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '2' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'da silva dias'  AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '3' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana'       AND sobrenome      REGEXP 'da silva dias'   AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '4' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana da'    AND sobrenome      REGEXP 'silva dias'      AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '5' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'silva dias'     AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '6' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana'       AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '7' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana'       AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '8' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'leidiana'       AND tipo <> '7') 
UNION DISTINCT (SELECT  DISTINCT '9' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'leidiana da'    AND tipo <> '7')   ORDER BY sb

The result:

2 - leidiana da silva dias
3 - leidiana da silva dias
4 - leidiana da silva dias
5 - leidiana da silva dias
6 - leidiana da silva dias

7 - leidiana da silva dias

As you can see I tried to solve the problem and ended up putting everything into distinct. rs

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无力看清 2024-12-10 06:52:57

您强制联合的结果与第一列 (sb) 不同。您可能可以使用外部 GROUP BY 来解决该问题:

SELECT min(sb) AS sb, name, id,sobrenome,nasc,genero,escol
FROM (
      (SELECT  '1' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana da'    AND tipo <> '7') 
UNION (SELECT  '2' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'da silva dias'  AND tipo <> '7') 
UNION (SELECT  '3' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana'       AND sobrenome      REGEXP 'da silva dias'   AND tipo <> '7') 
UNION (SELECT  '4' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana da'    AND sobrenome      REGEXP 'silva dias'      AND tipo <> '7') 
UNION (SELECT  '5' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'silva dias'     AND tipo <> '7') 
UNION (SELECT  '6' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana'       AND tipo <> '7') 
UNION (SELECT  '7' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana'       AND tipo <> '7') 
UNION (SELECT  '8' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'leidiana'       AND tipo <> '7') 
UNION (SELECT  '9' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'leidiana da'    AND tipo <> '7')) sbs
GROUP BY name, id,sobrenome,nasc,genero,escol
ORDER BY sb

You are forcing the results across the unions to be distinct with the first column (sb). You could probably solve the problem with an outer GROUP BY:

SELECT min(sb) AS sb, name, id,sobrenome,nasc,genero,escol
FROM (
      (SELECT  '1' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana da'    AND tipo <> '7') 
UNION (SELECT  '2' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'da silva dias'  AND tipo <> '7') 
UNION (SELECT  '3' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana'       AND sobrenome      REGEXP 'da silva dias'   AND tipo <> '7') 
UNION (SELECT  '4' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana da'    AND sobrenome      REGEXP 'silva dias'      AND tipo <> '7') 
UNION (SELECT  '5' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'silva dias'     AND tipo <> '7') 
UNION (SELECT  '6' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana'       AND tipo <> '7') 
UNION (SELECT  '7' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE nome          REGEXP 'leidiana'       AND tipo <> '7') 
UNION (SELECT  '8' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'leidiana'       AND tipo <> '7') 
UNION (SELECT  '9' as sb,nome,id,sobrenome,nasc,genero,escol FROM usuarios WHERE sobrenome     REGEXP 'leidiana da'    AND tipo <> '7')) sbs
GROUP BY name, id,sobrenome,nasc,genero,escol
ORDER BY sb
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文