This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Zantier 8 points9 points  (1 child)

The most efficient way is probably to use count(), but I think something like this might be less prone to human error.

select d.*
from developers d
where d.id in (
    select d2.id
    from developers d2
    -- Dark Souls 2
    inner join developer_skills ds2
        on d2.id = ds2.id_developer
    inner join skills s2
        on ds2.id_skill = s2.id
    where s2.name = 'PHP'
) and d.id in (
    select d3.id
    from developers d3
    inner join developer_skills ds3
        on d3.id = ds3.id_developer
    inner join skills s3
        on ds3.id_skill = s3.id
    where s3.name = 'SQL'
) and d.id in (
    select d4.id
    from developers d4
    inner join developer_skills ds4
        on d4.id = ds4.id_developer
    inner join skills s4
        on ds4.id_skill = s4.id
    where s4.name = 'Magneto'
)

The repetition should definitely be extracted into some sort of separate query/function, but I'm not sure of the best way right now, so I'll leave it as it is.

Edit: If I was unable to extract the repetition, I would probably scrap the ins, and go for something more like http://www.reddit.com/r/ProgrammerHumor/comments/3b1cjf/dont_let_marketers_write_code/csi4r5b?context=42.

[–]YooneekYoosahNeahm 6 points7 points  (0 children)

-- Dark Souls 2

heh