I am new to sql.i am little bit confused in the concept of group by.
Please suggest me online sites.books for detailed knowledge of sql

i have 2 tables
1)emp :empid empname empphone dept_id
2)dept :dept_id,dept_name

select dept_id,count(*) from emp group by dept_id;

its give the expected result.

dept_id count(*)
1 3
2 5

i want dept_name also.i am using join with this but giving a error not a group by expression

my query is:

select emp.dept_id,dept.dept_name,count(*) from dept INNER JOIN emp ON dept.dept_id=emp.dept_id group by emp.dept_id;

need suggestions..

You have three fields in the select statement, so you need at least two of them in the group by portion of your query

select emp.dept_id,dept.dept_name,count(field you are counting)
from dept INNER JOIN emp ON dept.dept_id=emp.dept_id 
group by emp.dept_id, dept.dept_name
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.