Note. Using MySQL 4.0, which means no subqueries (currently).
I have 2 tables:
- Table "user_details"
- A skills table in which there is a user_id and skill_id, which maps to a predefined set of skills defined elsewhere.
The current request allows the administrator to search for users by selecting skills, and the request works using OR, for example:
LEFT JOIN skills ON (ud.user_id = skills.user_id) WHERE skills.skill_id in (51, 52, 53, 54, 55) GROUP BY ud.user_id
This returns too many records, and therefore I want this search field to work in the AND module, where the user must have ALL selected skills that will be returned in the search.
You might be able to upgrade MySQL if subqueries are the best option.
edit: Do something with the group by, count, have, etc. Can you limit a team group to the requirement of how many matching lines you return? (e.g. 5 in this example).
edit2: Testing:
HAVING COUNT( * ) > 5
source share