Jump to content

Running where on joined tables


plazma

Recommended Posts

Hi Guys, i really hope someone out there will be able to help me, i have been trying to figure this one out for a week.

 

i have a couple of tables named,

Candedates

Skills

CandedateSkills

 

The aim of this page is to match a cendadates skills with a particular job.

each candedate has and id

ID    Candedate

1      Nick

2      Terry

3      James

In the skills table is a list of skills each having an id

for example

ID    Skill

1    math

2    english

3    science

 

in the candedateSkills are records with the candedats id and the skills that they have and their grade

Candedate    Skill    Grade

1                  1          4

1                  2          4

1                  3          4

meaning that Nick's skills are maths, english and science.

 

What i am tring to achieve is a sql statement where i can ask show me all the candedates where their skills are english grades maths and science with their grade,

 

in a plain english version of the query would be: tell me all the candedates who have a grade 4 in english and a grade 4 in science and a grade 4 in science

 

Thanks in advance, ive been reading the forum but have yet to find something that fits my particular situation

 

Link to comment
Share on other sites

Oh i thought i already had.

on the candedates table

 

ID    Candedate

1      Nick

2      Terry

3      James

 

on the skills table

 

ID    Skill

1    math

2    english

3    science

 

on the candedate skills table

 

Candedate    Skill    Grade

1                  1          4

1                  2          4

1                  3          4

 

Thanks for the quick reply

Link to comment
Share on other sites

Thanks for the reply zenag,

Ive tried the code out and am still running into some problems in the where clause.

Because i would be looking for something like

SELECT STATEMENTS HERE

where

Skill = 1(the skill ID) and grade = 1 (the value of the grade)

 

But there may be many criteria like

Skill = 1(the skill ID) and grade = 1 (the value of the grade)

Skill = 2(the skill ID) and grade = 4 (the value of the grade)

Skill = 3(the skill ID) and grade = 2 (the value of the grade)

and only supply a record if all criteria is met

 

Just not sure how to work out the where part of the statement, i appreciate the help

Link to comment
Share on other sites

I'm not sure what you mean... you mean you want all matching pairs of (skillID, gradeValue)? That's not "all" criteria... unless you want only the ones where at least one row matches each one? Please clarify.

Link to comment
Share on other sites

Thanks for the replies everyone,

yeah i am trying to filter out the records where all the skillID and gradeValue criteria pairs are met,

So far what i have is

 

select * from candedates join candedateskills on candedateskills.candedateid = candedates.id  join skills on

skills.id = candedateskills.skillid where (candedateskills.skillid = '2' and skillvalue = '1') and (candedateskills.skillid = '10' and skillvalue = '1')

I think i may be taking the wrong approach

Link to comment
Share on other sites

where (candedateskills.skillid = '2' and skillvalue = '1') and (candedateskills.skillid = '10' and skillvalue = '1') 

(specify TABLE NAME BEFORE  skillvalue in where clause like candedateskills.skillid )

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.