具有多联合的重复条目
我有这个
(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您强制联合的结果与第一列 (
sb
) 不同。您可能可以使用外部GROUP BY
来解决该问题:You are forcing the results across the unions to be distinct with the first column (
sb
). You could probably solve the problem with an outerGROUP BY
: