i have two tables for example
users
----------------------------------
id | name | blah
----------------------------------
1 | Samy | stackoverflow
2 | jhon | some thing
----------------------------------
skills
---------------------------------------
id | user_id | skill_title | level
---------------------------------------
1 | 1 | php | good
2 | 1 | css | excellent
3 | 1 | photoshop | fair
4 | 2 | php | good
---------------------------------------
and i run query like this
SELECT * FROM users
INNER JOIN skills ON users.id = skills.user_id
WHERE ($skill_title[0] LIKE 'skills_title' AND
$skill_title[1] LIKE 'skills_title')
where $skill_title is an array
what i need is to select user who have all this skills ie PHP,CSS
if i did query like above it will never bring data because it compare every single record to all array element AND if i replaced and with Or it will work but it will no’t bring user with all skills
any ideas ?
@joeshmo’s answer is probably your best solution, but it might be worth giving this a try as well. It might be faster if you have a ton of users, but very few that have the skill you’re looking for:
And your PHP script might look like this:
Another possible solution would be to use multiple
INNER JOINs, as @joeshmo suggested. You might be able to make it a bit smaller and cleaner by doing this:So your PHP script might look something like this:
I would try both solutions to see which one performs better for your data set.