Query a database or data for duplicate records in a single column

In MS-access, how to get the "identifier" of records that have duplicate content in the "myData" column?

sort of:

----------------------             ------------------------         
  ID   |   myData    |             |   ID   |   myData    |   
----------------------             ------------------------
   1   |   AAA       |             |    1   |   AAA       |
----------------------             ------------------------
   2   |   BBB       |             |    5   |   AAA       |
----------------------    ==>      ------------------------
   3   |   CCC       |             |    2   |   BBB       |
----------------------             ------------------------
   4   |   BBB       |             |    4   |   BBB       |
----------------------             ------------------------
   5   |   AAA       |
----------------------             

All I can do so far is this request:

SELECT        myData, COUNT(myData) AS Expr1
FROM            fooDB
GROUP BY myData
HAVING        (COUNT(myData) > 1)

which returns only a list of duplicate entries from "mydata" and the number of occurrences, adding something else is not performed at runtime. (and not ID)

OR

Saying that I am accessing the database as a DataTable in C #, how do I do this? Especially if this table has 2000 entries.

(maybe some help on how to work with INTERSECT so that it returns full rows having duplicates in the same column)

Thank.

+3
4

, Access , SQL- :

SELECT
    id,
    my_data
FROM
    My_Table
WHERE
    my_data IN
    (
        SELECT
            my_data
        FROM
            My_Table
        GROUP BY
            my_data
        HAVING
            COUNT(*) > 1
    )
+1
SELECT ID, fooDB.myData
FROM (
  SELECT myData
  FROM fooDB
  GROUP BY myData
  HAVING COUNT(myData) > 1
) t INNER JOIN fooDB ON (t.myData = fooDB.myData)
+2

Just throw it away ...

SELECT distinct
    f.ID,
    f.myData
FROM 
    fooDB f
    inner join fooDB f2 on f.myData = f2.myData
        and f.ID <> f2.ID
+1
source

Try

SELECT ID
  FROM fooDB
  WHERE myData IN (SELECT myData
                     FROM (SELECT myData, COUNT(myData) AS ROW_COUNT
                             FROM fooDB
                             GROUP BY myData)
                     WHERE ROW_COUNT > 1)

Share and enjoy.

0
source

Source: https://habr.com/ru/post/1752338/


All Articles