在SQL DB中查找重复条目并仅显示一个条目

时间:2017-07-12 05:25:21

标签: sql database

我有一张这样的表:

   Name    |   Text
-----------------------
 ALM_1234  |  Language1
 ALM_1234  |  Language2
 ALM_4321  |  Language1
 ALM_9876  |  Language1

我需要一个SQL查询,只显示一个带有一个文本的重复条目。两个文本中的哪一个显示无关紧要。 像这样:

   Name    |   Text
-----------------------
 ALM_1234  |  Language1
 ALM_4321  |  Language1
 ALM_9876  |  Language1

非常感谢任何帮助。

5 个答案:

答案 0 :(得分:1)

使用Group ByMin/Max汇总

Select Name,Min(Text) as Text
From yourtable
Group by Name

答案 1 :(得分:0)

使用GROUP BY,因为它会删除除第一列之外的所有列

select name, text from table group by name;

答案 2 :(得分:0)

尝试使用DISTINCT命令:

SELECT DISTINCT(Name) FROM table_name;

答案 3 :(得分:0)

在您的查询中使用,例如此查询:

A = Matrix([[ 1,    0,   0,    0,    0,    0,     0,   0,   0,     0,    0,     0,    0,   0,     0,   0],
        [ 0,    0,   0,    1,    0,    0,     0,   0,   0,     0,    0,     0,    0,   0,     0,   0],
        [-1,    6, -12,    8,    0,    0,     0,   0,   0,     0,    0,     0,    0,   0,     0,   0],
        [-8,   36, -54,   27,    0,    0,     0,   0,   0,     0,    0,     0,    0,   0,     0,   0],
        [ 0,    0,   0,    0,    0,    0,     0,   0,   0,     0,    0,     0,    1,   0,     0,   0],
        [ 0,    0,   0,    0,    0,    0,     0,   0,   0,     0,    0,     0,    0,   0,     0,   1],
        [ 0,    0,   0,    0,    0,    0,     0,   0,   0,     0,    0,     0,   -1,   6,   -12,   8],
        [ 0,    0,   0,    0,    0,    0,     0,   0,   0,     0,    0,     0,   -8,  36,   -54,  27],
        [-1,    0,   0,    0,    6,    0,     0,   0, -12,     0,    0,     0,    8,   0,     0,   0],
        [ 0,    0,   0,   -1,    0,    0,     0,   6,   0,     0,    0,   -12,    0,   0,     0,   8],
        [ 1,   -6,  12,   -8,   -6,   36,   -72,  48,  12,   -72,  144,   -96,   -8,  48,   -96,  64],
        [ 8,  -36,  54,  -27,  -48,  216,  -324, 162,  96,  -432,  648,  -324,  -64, 288,  -432, 216],
        [-8,    0,   0,    0,   36,    0,     0,   0, -54,     0,    0,     0,   27,   0,     0,   0],
        [ 0,    0,   0,   -8,    0,    0,     0,  36,   0,     0,    0,   -54,    0,   0,     0,  27],
        [ 8,  -48,  96,  -64,  -36,  216,  -432, 288,  54,  -324,  648,  -432,  -27, 162,  -324, 216],
        [64, -288, 432, -216, -288, 1296, -1944, 972, 432, -1944, 2916, -1458, -216, 972, -1458, 729]])
assert A * Matrix(_Z) == AA
linsolve((A, bb))

如果你想找到重复的查询,你应该使用这个:

Select Text From yourtable Group by Text having count(*)>1
祝你好运

答案 4 :(得分:0)

distinct子句将起作用

select distinct name,text from table