开发者

MySQL query to search for people with specific skills

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    Us开发者_JAVA技巧er_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.


I would recomend that you have a look at Group_Concat

GROUP_CONCAT useful GROUP BY extension.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜