MySQL 中特定的重复选择
我确实查看了 SO 的内部和外部,但仍然不知道这是否可以做到。我有一个如下所示的表:
User ID | Role | First Name | Last Name | Email |<br>
0001 | K | John | Smith | [email protected]|<br>
0002 | Q | Jane | Dickens | [email protected]|<br>
0003 | K | John | Smith | [email protected]|<br>
0004 | J | Jack | Paper | [email protected]|<br>
如您所见,由于用户两次单独输入信息,该表包含重复项。我想显示的行
我可以获得前三个条件来使用内连接子查询,但是当我尝试添加第四个条件时,我得到 0 返回结果。
预先感谢您的帮助!
I did take a look in and outside of SO and still don't know if this can be done. I have a table that looks like this:
User ID | Role | First Name | Last Name | Email |<br>
0001 | K | John | Smith | [email protected]|<br>
0002 | Q | Jane | Dickens | [email protected]|<br>
0003 | K | John | Smith | [email protected]|<br>
0004 | J | Jack | Paper | [email protected]|<br>
As you can see, the table contains a duplicate due to a user entering their information two separate times. I want to display the rows that
I can get the first three conditions to work with an inner join subquery, but I get 0 returned results when ever I try to to add in the fourth condition.
Thanks in advance for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
将给出一个像
这样的表。技巧是对除
ID
之外的所有内容进行GROUP BY
。您也可以这样做:
要得到
无论如何,您明白了如何根据您的目的改变它。
Will give a table like
The trick is to
GROUP BY
everything exceptID
.You could also do:
to get
Anyhow, you get the point of how to vary it to your purposes.
尝试类似的方法:
Try something like:
我假设您的表不包含真正的重复行(其中用户 ID 也匹配)。我认为获取相关行应该像这样简单(使用我调整后的列和表命名方案):
I am assuming that your table does not contain true duplicate rows (where the User ID also matches). I think it should be as simple as this to get the relevant rows back (with my adjusted column and table naming scheme):
我会使用 count(*) 和 group by 子句。
像这样
SELECT count(*) as
count
FROM table group by concat(firstname,'\n',last_name) withcount
=1;I would use count(*) and group by clause.
Like this
SELECT count(*) as
count
FROM table group by concat(firstname,'\n',last_name) havingcount
=1;我认为您想删除重复的行。仅按分组进行计数并删除重复的行。
I think you want to delete duplicate rows. Only take count by group by and delete duplicate rows.
您不必下载扩展;转到左下角,单击设置,单击键盘快捷键,然后搜索“重复”。您应该看到如下图所示并分配您想要的组合键。我选择shift+D是因为我不想失去ctrl+D当前的行为,它也非常有益。
You don't have to download extensions; go left bottom corner, click settings, click Keyboard Shortcuts, and search "duplication". You should see as in the below image and assign the key combination you want. I choose shift+D because I don't want to lose the current behavior of ctrl+D it is also very beneficial.