在MS访问中,如何获取“myData”列中具有重复内容的记录的“ID”?
类似的东西:
---------------------- ------------------------
ID | myData | | ID | myData |
---------------------- ------------------------
1 | AAA | | 1 | AAA |
---------------------- ------------------------
2 | BBB | | 5 | AAA |
---------------------- ==> ------------------------
3 | CCC | | 2 | BBB |
---------------------- ------------------------
4 | BBB | | 4 | BBB |
---------------------- ------------------------
5 | AAA |
----------------------
我所能做的就是这个查询:
SELECT myData, COUNT(myData) AS Expr1
FROM fooDB
GROUP BY myData
HAVING (COUNT(myData) > 1)
只返回“mydata”中重复记录的列表和出现次数,在执行时添加任何其他内容都将失败。 (而且没有ID)
或
说我在C#中将数据库作为DataTable访问,如何管理?特别是当这张表有大约2000条记录时。
(或许有一些帮助,如何使用 INTERSECT 让它返回在一列上有重复的完整行)
感谢。
答案 0 :(得分:2)
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)
答案 1 :(得分:1)
我不知道你是否可以像这样在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
)
答案 2 :(得分:1)
把它扔到那里......
SELECT distinct
f.ID,
f.myData
FROM
fooDB f
inner join fooDB f2 on f.myData = f2.myData
and f.ID <> f2.ID
答案 3 :(得分:0)
尝试
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)
分享并享受。