Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have two table Employee(EName, ESalary, ELocation) and Locations(s.no, Location).
I want to print number of employees in each city.

Like ....

NY 3
LA 4
Miami 1
Chicago 7

Layout does not matter. Actually printing does not matter.
I just need the SQL Query to retrieve this.
Posted
Updated 16-Nov-13 19:06pm
v2

try this
select ELocation ,COUNT(EName) from Employee group by ELocation;
SQL

 
Share this answer
 
You have not been clear about the table schemas, but assuming that [s.no] is the primary key on table [locations] and[Location] contains the name; and that [ELocation] provides the foreign key to that table on [Employee] then you want something like this...
SQL
select Location, count(Ename) 
from locations L
LEFT OUTER JOIN Employee E ON L.[s.no]=E.ELocation
GROUP BY Location

Note that I've surrounded [s.no] with square brackets as the period (.) in the name is not valid otherwise

This query should return the expected results in your post
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900