show duplicate rows in access

僤鯓⒐⒋嵵緔 提交于 2019-12-24 06:03:30

问题


i have this table

MEN

id    |   Qty   |  Place
========================
111   |  10     |  55
111   |  20     |  66
111   |  10     |  77
222   |  40     |  11
333   |  50     |  11
111   |  10     |  22
222   |  44     |  33
222   |  40     |  44
333   |  15     |  55

i need to show all the records that id=id and Qty=Qty like this:

id    |   Qty  |  Place
=====================
111   |  10    |  55
111   |  10    |  77
111   |  10    |  22
222   |  40    |  11
222   |  40    |  44

回答1:


You can do something like this:

SELECT MEN.Id, MEN.Qty, MEN.Place
FROM MEN INNER JOIN
(SELECT MEN.Id, MEN.Qty
 FROM MEN
 GROUP BY MEN.Id, MEN.Qty
 HAVING (((Count(*))>1)))  AS a
ON (MEN.Qty = a.Qty) AND (MEN.Id = a.Id)
ORDER BY MEN.Id, MEN.Qty;

Create the inner query to find where there are more than one instances of the Id then join it back to the original table to get the Place values.




回答2:


Try this

SELECT T.ID,T.Qty
FROM Table1 T
GROUP BY T.ID,T.Qty
HAVING (((Count(*))>1));

Use Below query to get full set of record details:

SELECT R.Id, R.Qty, R.Place
FROM Table1 R INNER JOIN
(
 SELECT T.Id, T.Qty
 FROM Table1 T
 GROUP BY T.Id, T.Qty
 HAVING (((Count(*))>1))
)AS JR ON R.Qty = JR.Qty AND R.Id = JR.Id


来源:https://stackoverflow.com/questions/24363914/show-duplicate-rows-in-access

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!