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
 Sql Syntax

Author  Topic 

nkmekal
Starting Member

4 Posts

Posted - 2009-03-25 : 15:38:03
Hi All I am new to database world and i am facing real difficult tasks due to my poor sql writing skill. So to improve my Sql skills i have crreated a sample database and i am running different types of queries to test my strengths.
Now i have a really perplexed situation as follows.

I have three tables in my database they are employee, Designation and an assosiate table between these two tables. Now an Employee can have or more designations and each designation can have one or more employees.

Now I am trying to write a query that would return employee list based on sql like syntax. So when i queried with a like condition i got more than 1000 records for a criteria but also i want to know the number of employees in each designation category.

CAN ANYONE HELP ME OUT IN THIS ASPECT.



MNK

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-03-25 : 15:45:25
Show us what you tried, the data in the tables, and the expected output of the query.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

nkmekal
Starting Member

4 Posts

Posted - 2009-03-25 : 16:00:52
Hi thanx for the immediate reply.

I tried this
Select Employee.Name FROM EMPLOYEE WHERE Employee.Name like '%Txt%'

Now this query works fine and its returning more than 1000 records. But what should I do if i want to know how many employees from these records are Developers or DBA or PM etc.

Expected Output
DesignationName| Number
---------------|--------|
Developer 300
DBA 100
Project Managers 500

Here are the Tables with some sample data
EMPLOYEE
Emp_Id | Name
-------|------
1 AAA
2 BBB
3 CCC

ASSOCIATE TABLE

Emp_ID | Id
-------|----
1 1
1 3
2 4

DESIGNATION

Id | Name
---|-----|
1 Developer
2 DBA
3 Project Manager
4 Team Leader





MNK
Go to Top of Page

matty
Posting Yak Master

161 Posts

Posted - 2009-03-26 : 00:31:45
You have to use GROUP BY.
Go to Top of Page
   

- Advertisement -