plazma Posted June 16, 2008 Share Posted June 16, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/110402-running-where-on-joined-tables/ Share on other sites More sharing options...
zenag Posted June 16, 2008 Share Posted June 16, 2008 can u show what are all the fields of Candedates Skills CandedateSkills Quote Link to comment https://forums.phpfreaks.com/topic/110402-running-where-on-joined-tables/#findComment-566394 Share on other sites More sharing options...
plazma Posted June 16, 2008 Author Share Posted June 16, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/110402-running-where-on-joined-tables/#findComment-566398 Share on other sites More sharing options...
zenag Posted June 16, 2008 Share Posted June 16, 2008 SELECT candedates.candedate,skills.skill,cande.grade FROM candedates,cande,skills WHERE candedates.id=cande.candedate and cande.skill=skills.id Quote Link to comment https://forums.phpfreaks.com/topic/110402-running-where-on-joined-tables/#findComment-566434 Share on other sites More sharing options...
zenag Posted June 16, 2008 Share Posted June 16, 2008 u can also use left join Quote Link to comment https://forums.phpfreaks.com/topic/110402-running-where-on-joined-tables/#findComment-566436 Share on other sites More sharing options...
zenag Posted June 16, 2008 Share Posted June 16, 2008 SELECT candedates.candedate,skills.skill,cande.grade FROM candedates LEFT JOIN cande ON candedates.id=cande.candedate LEFT JOIN skills ON cande.skill=skills.id WHERE ...any condition ... Quote Link to comment https://forums.phpfreaks.com/topic/110402-running-where-on-joined-tables/#findComment-566437 Share on other sites More sharing options...
plazma Posted June 16, 2008 Author Share Posted June 16, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/110402-running-where-on-joined-tables/#findComment-566461 Share on other sites More sharing options...
fenway Posted June 16, 2008 Share Posted June 16, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/110402-running-where-on-joined-tables/#findComment-566516 Share on other sites More sharing options...
plazma Posted June 16, 2008 Author Share Posted June 16, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/110402-running-where-on-joined-tables/#findComment-566881 Share on other sites More sharing options...
zenag Posted June 17, 2008 Share Posted June 17, 2008 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/110402-running-where-on-joined-tables/#findComment-566990 Share on other sites More sharing options...
fenway Posted June 17, 2008 Share Posted June 17, 2008 It can't be equal to two things at once; you need to use OR, and the check the count in a having clause. Quote Link to comment https://forums.phpfreaks.com/topic/110402-running-where-on-joined-tables/#findComment-567330 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.