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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 SQL Server Administration (2012)
 Counter sql
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

3 Posts

Posted - 05/14/2013 :  10:33:41  Show Profile  Reply with Quote

My boss ask me some information: How many properties has each estate agent in our database. I need your help please.

I have a database with estate agents and properties.
The properties are stored in table_ads:
id category userid ad_text
45 flat 236 flat for rent
46 house 237 house for rent
The estate agents are stored in table_ea:
id name username email password
236 Robert Royalestate x564d5s6s
237 David Boboestate x5s4yhhs6s

I would like to get a list of estate agents with the quantity of properties they have

username qty
Royalestate 18
Boboestate 26

So I need to creqate an SQL query which will count the quantity of each estate agent, display this quantity with the username.

Can you help me please?


Flowing Fount of Yak Knowledge

United Kingdom
2179 Posts

Posted - 05/14/2013 :  10:35:12  Show Profile  Visit jackv's Homepage  Reply with Quote
Could you supply the DDL of the tables - so we can understand the relationships of the tables, or is there just one table?

Jack Vamvas
Go to Top of Page

Starting Member

3 Posts

Posted - 05/14/2013 :  10:48:14  Show Profile  Reply with Quote
Thanks for this quick answer.

The relation is easy.

table_ads is connected to table_ea by
userid id

ps:sorry but for the form, the forum remove spaces.
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 05/14/2013 :  12:41:41  Show Profile  Reply with Quote
        COUNT(DISTINCT AS Properties
FROM    table_ea ea
        LEFT JOIN table_ads ad ON ad.userid =
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000