Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
SELECT *, count(ProjPK)  FROM tblEmp
WHERE Half = 1
GROUP BY ProjPK


This SQL statement returning me specific records but I want to get all records using above query
but also show totalProjectMember with every record
Posted
Updated 14-Apr-15 22:00pm
v2
Comments
Kornfeld Eliyahu Peter 15-Apr-15 3:56am    
This SQL query will not even run!
Muhamad Faizan Khan 15-Apr-15 4:00am    
i have updated with real sql. which i am trying
JoCodes 15-Apr-15 4:06am    
And whats the resultset you are getting from the updated query? is that only 1 record?
Muhamad Faizan Khan 16-Apr-15 0:33am    
i am getting 5 records with correct count numbers. but i want to get all records with correct count numbers. how can i do this OrignialGriff suggest me a join but i want to avoid it

1 solution

Try:
SQL
SELECT a.name, a.projId, b.totalProjectMember 
FROM tblEmp a
JOIN (SELECT projId, Count(*) AS totalProjectMember 
      FROM tblEmp 
      GROUP BY projId) b
ON a.projId = b.projId
 
Share this answer
 
Comments
Muhamad Faizan Khan 15-Apr-15 4:10am    
any solution without join? actually the query which ai am running already contain 3\4 joins
OriginalGriff 15-Apr-15 4:14am    
If you want to get the counts on a grouped basis, then no - you need to use a GROUP BY to group them togther!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900