Reputation: 65
I have two tables say Students and Class
St_ID int, St_Name nvarchar(100)
Cl_ID int, Cl_Name nvarchar(100).
I want to get duplicate name of students (and count) from each class how can I write the query?
Upvotes: 0
Views: 4412
Reputation: 2714
Assuming you have foreign key CL_ID
from Class
table in Student
table,
Select cl.CL_ID, st.St_Name, COUNT(st.St_ID)
From Student st
Inner Join Class cl On st.CL_ID = cl.CL_ID
Group By cl.CL_ID, st.St_Name
Having COUNT(st.St_ID) > 1
Upvotes: 1