重复SQL清单

时间:2018-09-13 09:29:42

标签: mysql sql

我有一个包含以下列的表格:

ID
Link
price

“链接”列中有一些重复项,如何获得重复项列表。

我的查询:

SELECT * 
FROM tbl
WHERE Link
IN
(SELECT Link
FROM tbl
GROUP BY Link
HAVING CONT(*) > 1;

它返回所有具有重复项的字段,但是我需要列出它们,这样我才能看到所有的字段(具有重复项的字段)。

3 个答案:

答案 0 :(得分:0)

尝试一下:

interface Callable {
public void callBackMethod();
}

class Worker {
// Worker gets a handle to the boss object via the Callable interface.
// There's no way this worker class can call any other method other than
// the one in Callable.
public void doSomeWork(Callable myBoss) {
    myBoss.callBackMethod();
    // ERROR!
    //myBoss.directMethod();
}
}

class Boss implements Callable {
public Boss() {
    // Boss creates a worker object, and tells it to do some work.
    Worker w1 = new Worker();
    // Notice, we're passing a reference of the boss to the worker.
    w1.doSomeWork(this);
}
//developer that develop library just call controll the place of calling

public void callBackMethod() {
    System.out.println("What do you want?");
}

public void directMethod() {
    System.out.println("I'm out for coffee.");
}
}

public class Main {

public static void main(String[] args) {

    Boss b = new Boss();
    b.directMethod();

    // write your code here
}
}

答案 1 :(得分:0)

您可以这样做:

SELECT Link, COUNT(*)
FROM tbl
GROUP BY Link
HAVING COUNT(*)>1

在MySQL中,您甚至可以从SELECT中忽略COUNT(*)

SELECT Link
FROM tbl
GROUP BY Link
HAVING COUNT(*)>1

答案 2 :(得分:0)

如果您想要完整的行,那么我建议:

select t.*
from tbl t
where exists (select 1
              from tbl t2
              where t2.link = t.link and t2.id <> t.id
             );

这假设id是唯一的,这似乎是一个合理的假设。