×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

sql gurus please

sql gurus please

sql gurus please

(OP)
Hi to all u SQL Gurus out there!
 
could someone help me with my query please?
 
 I have the following tables
 
Skill Attempt:        //holds all attempts at "skill" even failed and disqualified (for licences)
SkillAttemptID        //eg licence attempts etc
PersonID
AttemptDate
ValidTo
ProviderDI
SkillID
Result
Ref
Comments
 
Skill:                    //holds names of skills and time valid
SkillID
Name
TimeValid
CompanyID
 
SkillNeeded:            //holds what skills are required for what job
SkillNeededID
EmploymentID
TimePeriodID
SkillID
 
Employment:        //job names
EmploymentID
Name
 
TimePeriod:            //time periods in weeks for select box
TimePeriodID
Weeks
 
PersonEmployment:        //who does what jobs
PersonEmploymentID
CommenceDate
PersonID
 
PErson:
personid
name
etc
 
In the SkillNeeded table, some skills are required within a certain period of beginning a job.  these hold a foreign key linking to timeperiod
if the skill is a prerequisite, the value will be 0
if there is no time limit, the skillneeded.timeperiodid will be null - hence the left join
 
i have the following sql to show what skills a person requires that they do not yet have:
 
select distinct pe.commencedate, sn.skillid, s.name, sn.timeperiodid, tp.weeks
 from personemployment pe
join skillneeded sn on sn.employmentid = pe.employmentid
left join timeperiod tp on tp.timeperiodid = sn.timeperiodid
join skill s on s.skillid = sn.skillid
where pe.personid = 4
and sn.skillid not in
(select skillid from skillattempt where (personid = 4 and skillid = sn.skillid
and result = 'P' and (validto is null or validto > '02/11/2003')))
 
Some skills are required in more than one job.  If this person has both those jobs and doesnt have that skill, then the query returns the skill for as many times as it is needed.
 
What i really want, is for the skill itsself to be only returned once, with the earliest timeperiod.  Is this possible in SQL or do i need to frig with code? (distinct isnt working with all my joins)
 
 

RE: sql gurus please

LEFT join doesn't matter with NULLs - make it a LEFT OUTER join...

(as for the rest, I didn't check)

Martijn Tonies
InterBase Workbench - the developer tool for InterBase and Firebird
http://www.upscene.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close