Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Geting a name from a joined table after COUNT()

Author  Topic 

tuka
Starting Member

26 Posts

Posted - 2006-06-14 : 09:00:21
I am trying to get a recordset that gives me along with the id and count, the name (from another table) of a tradelead. Each time I reference a column from the other table, it breaks... I think I understand why but I am at a loss to figure out a solution.. any sugestions ?

THIS WORKS:
SELECT COUNT(tb_industry.id_industry) AS tlcount, tb_industry.id_industry
FROM tb_tradelead INNER JOIN tb_industry ON tb_tradelead.id_industry=tb_industry.id_industry
GROUP BY tb_industry.id_industry

BIT THIS FAILS....
SELECT COUNT(tb_industry.id_industry) AS tlcount, tb_industry.id_industry, tb_industry.name
FROM tb_tradelead INNER JOIN tb_industry ON tb_tradelead.id_industry=tb_industry.id_industry
GROUP BY tb_industry.id_industry

Server message
Column 'tb_industry.name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

TIA,
tuka

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-14 : 09:18:53
You should include that column in Group by Clause

SELECT COUNT(tb_industry.id_industry) AS tlcount, tb_industry.id_industry, tb_industry.name
FROM tb_tradelead INNER JOIN tb_industry ON tb_tradelead.id_industry=tb_industry.id_industry
GROUP BY tb_industry.id_industry,tb_industry.name



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

tuka
Starting Member

26 Posts

Posted - 2006-06-14 : 09:33:03
Thanks, that did it !
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-14 : 10:26:23
Also Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -