Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I list duplicate values out of a table? [duplicate]

Tags:

sql-server

I have this table. Some of the rows have duplicate values in the Kanji column.

How can I show these rows where the same Kanji appears more than once?

CREATE TABLE [dbo].[Phrase] (
    [PhraseId]              UNIQUEIDENTIFIER DEFAULT (newid()) NOT NULL,
    [English]               NVARCHAR (250)   NOT NULL,
    [Kanji]                 NVARCHAR (250)   NULL,
    PRIMARY KEY CLUSTERED ([PhraseId] ASC) );
like image 948
Alan2 Avatar asked May 16 '17 12:05

Alan2


1 Answers

You can use a GROUP BY statement by that column and specify a constraint that COUNT(*) of that group is larger than 1, so:

SELECT [kanji]
FROM [dbo].[Phrase]
GROUP BY [kanji]
HAVING COUNT(*) > 1
like image 81
Willem Van Onsem Avatar answered Oct 21 '22 06:10

Willem Van Onsem