tags:

views:

34

answers:

1

Hi,

I'm inexperienced with SQL... i'm trying to figure out how to search my database for personnel with specific skills.

I want to generate a table which contains two columns, Name and Skill(s)

The initial search is currently performing this query:

SELECT  * 
FROM    User_Skills LEFT JOIN 
     skills ON User_Skills.Skill_id = Skills.id 
WHERE   Skill_id = 5 OR Skill_id = 7 // 5 & 7 are variables.

This generates results like this:

User_id     Skill_id  id   name
1000           5     5  Designer
1000           7     7  Data Analysis
1001           7     7  Data Analysis
1001           5     5  Designer

The question is... am I doing this right? I'm searching for specific skills.. once I find the skills, should I then use the User_id's to perform a second query? I dont know if I need the name returned twice, as it would if I joined the Users table to the above query. Or should I JOIN the User table, then cull data I don't need programatically.

+2  A: 

I would recomend that you have a look at Group_Concat

GROUP_CONCAT useful GROUP BY extension.

astander
That's really cool! I've never used the GROUP functions in SQL!Being very new with databases, I'm wondering if you could point me in the right direction.I don't know how to THINK about how to get there results I want.Say if I want to return all users who have skill id 10 and skill id 12, When I query using WHERE SKill_id = 10 AND Skill_id = 12, it shows no results. If I do Skill_id = 10 OR Skill_id = 12, it won't give me the results I want because I need users who have BOTH skills, not one or the other.These are the results I'd like: User Skill_id Fred 10,11
Samuurai