Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Quick access
Question
Hi All,
I need a help in writing a simple SQL for the following requirement. Below is the table design:
Naomi N
Employee(EmpID, Name)
Siriusware 0
Partner Sign in Skill(SkillID, SkillName)
blogs.lessthandot.c... to vote
EmployeeSkills(EmpID, SkillID)
206,645 Points 14 14 24
I am an IT professional with more than 15 Give the list of employees only if they have all the skills specified. For example: Emp 1 has Skill1,
years of experience in variety of Skill2, Skill4 & Emp2 has Skill1, Skill2, Skill3 skills. If we pass Skill1, Skill2, Skill3 as input, only Emp2
programming languages and should be displayed since he has all the skills.
technologies. I am a Microsoft Community
Award Recipient and Personality of the Thanks in Advance !
Year at UniversalThread.com forum in
2008,2009,2010,2011. I am also a TechNet
Guru competition multi times Gold Wednesday, May 28, 2014 4:55 PM
Winner.
Reply | Quote PSK1990 0 Points
Naomi N's threads
View Profile
Answers
Top related threads
Refactor TSQL Query Help Needed
This is a typical relational division problem.
TSQL Query need help
Take a look at this article
T-SQL query... Need help
Newbie Need help with tsql query T-SQL: Relational Division
1
need help with a T-SQL query Sign in select E.* from Employee E inner join EmployeeSkills ES ON E.EmpID = ES.EmpID INNER JOIN Skills
to vote S ON ES.SkillID = S.SkillID
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles
Reply | Quote
Naomi N Siriusware (Partner) 206,645 Points
All replies
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/e8e018eb-7ffd-4ff2-afc2-042b384ce1aa/tsql-query-help-needed?forum=transactsql 1/5
7/4/2014 T-SQL Query help needed
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles
Reply | Quote
Naomi N Siriusware (Partner) 206,645 Points
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/e8e018eb-7ffd-4ff2-afc2-042b384ce1aa/tsql-query-help-needed?forum=transactsql 2/5
7/4/2014 T-SQL Query help needed
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles
Because I assumed we're passing Skill Names, not IDs from the interface. If we passed Ids, then we
don't need to join with the Skills table.
For every expert, there is an equal and opposite expert. - Becker's Law
1
Sign in
to vote My blog
My TechNet articles
Reply | Quote
Naomi N Siriusware (Partner) 206,645 Points
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/e8e018eb-7ffd-4ff2-afc2-042b384ce1aa/tsql-query-help-needed?forum=transactsql 3/5
7/4/2014 T-SQL Query help needed
Doing a raw count of kills/employee doesn't account for data integrity problems in the database.
Say Empl2 has two records in the EmployeeSkills table for Skill1, and raw count would yield 4 and
Emp2 wouldn't be returned. Sure that problem could be resolved by adding a count(distinct
SkillID) but I believe there's a better way to solve the problem:
0
Sign in
declare @Employee table (EmpID int, Name varchar(100))
to vote declare @Skill table (SkillID int, SkillName varchar(100))
declare @EmployeeSkills table (EmpID int, SkillID int)
;with MissingSkills
as
(
select distinct
es.EmpID
from @SkillList as l
right join @EmployeeSkills as es
on l.SkillID = es.SkillID
where l.SkillID is null
)
select e.*
from @Employee as e
left join MissingSkills as m
on m.EmpID = e.EmpID
where m.EmpID is null
When I say better, I'm talking about accuracy. Performance might be a different story.
0
Sign in
select emp.EmpID from
to vote Skill sk join EmployeeSkills emp
on sk.SkillID = emp.SkillID
where emp.SkillID in (select SkillID from @SkillList) group by emp.EmpID having count(*) = (select COUNT
Thanks. BalaKrishnan
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/e8e018eb-7ffd-4ff2-afc2-042b384ce1aa/tsql-query-help-needed?forum=transactsql 4/5
7/4/2014 T-SQL Query help needed
Hi,
See http://msdn.microsoft.com/en-us/library/ms178543.aspx
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/e8e018eb-7ffd-4ff2-afc2-042b384ce1aa/tsql-query-help-needed?forum=transactsql 5/5