本文介紹了在 MySQL 中查找重復(fù)值的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我有一個(gè)帶有 varchar 列的表,我想在該列中查找所有具有重復(fù)值的記錄.我可以用來(lái)查找重復(fù)項(xiàng)的最佳查詢是什么?
I have a table with a varchar column, and I would like to find all the records that have duplicate values in this column. What is the best query I can use to find the duplicates?
推薦答案
使用 GROUP BY
子句執(zhí)行 SELECT
.假設(shè) name 是您要在其中查找重復(fù)項(xiàng)的列:
Do a SELECT
with a GROUP BY
clause. Let's say name is the column you want to find duplicates in:
SELECT name, COUNT(*) c FROM table GROUP BY name HAVING c > 1;
這將返回一個(gè)結(jié)果,第一列中的 name 值,以及該值在第二列中出現(xiàn)的次數(shù).
This will return a result with the name value in the first column, and a count of how many times that value appears in the second.
這篇關(guān)于在 MySQL 中查找重復(fù)值的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!