Click here to Skip to main content
15,887,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have 2 tables,
1. tbl_emp1,(primary key is Id)
2. tbl_emp2(foreign key is emp1id).
SQL
select count(emp1id) from tbl_emp2 group by emp1id


Above query returns,
1
2
3
7
2
3
2

I want only 3,7,3. Not less than 3.
Posted
Updated 19-Jun-13 2:27am
v4
Comments
CHill60 23-Mar-13 8:35am    
Not sure what your second query is all about - an id is not a count. For your first query I think you should have select emp1id, count(emp1id) from tbl_emp2 groupy by emp1id having count(*) > 2
Maciej Los 24-Mar-13 10:42am    
You should post it as an answer.
My virtual 5!
CHill60 24-Mar-13 12:22pm    
Thank you ! As the OP has thanked me I have indeed posted it as an answer
Mohankumar.Engain 23-Mar-13 8:49am    
thanks chill60.

1 solution

Prompted by Maciej Los and as the OP has thanked me I'll post this as the solution.
For your first query I think you should have
SQL
select emp1id, count(emp1id) from tbl_emp2 groupy by emp1id having count(*) > 2
 
Share this answer
 
Comments
Maciej Los 24-Mar-13 12:32pm    
A 5!

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