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.
| 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 |
|
|
nkmekal
Starting Member
4 Posts |
Posted - 2009-03-25 : 16:00:52
|
| Hi thanx for the immediate reply.I tried thisSelect 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 OutputDesignationName| Number ---------------|--------| Developer 300 DBA 100Project Managers 500 Here are the Tables with some sample dataEMPLOYEE Emp_Id | Name -------|------ 1 AAA 2 BBB 3 CCCASSOCIATE TABLEEmp_ID | Id-------|---- 1 1 1 3 2 4DESIGNATION Id | Name---|-----| 1 Developer 2 DBA 3 Project Manager 4 Team Leader MNK |
 |
|
|
matty
Posting Yak Master
161 Posts |
Posted - 2009-03-26 : 00:31:45
|
| You have to use GROUP BY. |
 |
|
|
|
|
|