If you use SQL Server, then you can try something like this:
DECLARE @tmp TABLE (ADminNo VARCHAR(30), PaperNo INT)
INSERT INTO @tmp (AdminNo, PaperNo)
SELECT '111411H', 3
UNION ALL SELECT '111411H', 18
UNION ALL SELECT '172828z', 3
UNION ALL SELECT '172828z', 18
UNION ALL SELECT '111380Y', 93
UNION ALL SELECT '111938S', 10
SELECT t1.AdminNo, COUNT(t1.AdminNo) AS NumberOfStudents, STUFF( (SELECT ', ' + CONVERT(VARCHAR(5),[PaperNo]) AS 'text()'
FROM @tmp AS t2
WHERE t2.AdminNo = t1.AdminNo
FOR XML PATH('')), 1, 1, '') AS [ConflictingPaper]
FROM @tmp AS t1
GROUP BY AdminNo
HAVING COUNT(AdminNo)>1
Result:
AdminNo NumberOfStudents ConflictingPaper
111411H 2 3, 18
172828z 2 3, 18
[EDIT]
12345_abcde wrote:
data is retrieved from access database and stored in datatable. using with vb.net
So... You can use below query:
SELECT t1.AdminNo, COUNT(t1.AdminNo) AS NumberOfStudents
FROM @tmp AS t1
GROUP BY AdminNo
HAVING COUNT(AdminNo)>1
It will return the same result as above, but without the
ConflictingPaper
column.
How to fetch data from MS Access database? Please, read this:
Accessing Microsoft Office Data from .NET Applications[
^]
[/EDIT]