SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Geting a name from a joined table after COUNT()
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

tuka
Starting Member

26 Posts

Posted - 06/14/2006 :  09:00:21  Show Profile
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

India
22769 Posts

Posted - 06/14/2006 :  09:18:53  Show Profile  Send madhivanan a Yahoo! Message
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 - 06/14/2006 :  09:33:03  Show Profile
Thanks, that did it !
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22769 Posts

Posted - 06/14/2006 :  10:26:23  Show Profile  Send madhivanan a Yahoo! Message
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
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000