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
 General SQL Server Forums
 New to SQL Server Programming
 How to get count of another table in a select?

Author  Topic 

WarrenW
Starting Member

20 Posts

Posted - 2014-11-05 : 16:37:36
Hello everyone,

I can't seem to get this script to work right so I need some help. I have two tables. Houses and Guests. The guests are the people who visited the houses tied by the HouseNo.

I want to list all of the houses which has HouseName, Address, HouseNo. Then I want to show a column for the number of guests who visited it.

The Guest table has GuestName and HouseNo. How can I do a select on all houses and then show a column of COUNT(GuestName) for all the guests with the HouseNo matching each row?

Any help would be appreciated!

Warren

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2014-11-05 : 16:43:37
Join the two tables, then group by HouseName, Address, HouseNo, finally, count the rows in each grouping using count(*)



No amount of belief makes something a fact. -James Randi
Go to Top of Page
   

- Advertisement -