Subject Re: [firebird-support] Tricky SQL
Author Helen Borrie
At 05:33 PM 12/06/2004 +0100, you wrote:
>Hi - tricky SQL - consider a pair of tables in a 1>M relationship:
>
>master table VACANCY with it's own unique ID and a SKILLS
>table recording variable number of skills per vacancy.
>
>Question I have is the SQL to extract the Vacancies
>for a user-defined number of skills.
>
>ie - user wants all vacancies with SKILL1, SKILL4 and SKILL8
>in - just these 3, no more, no less.
>
>Have been experimenting wit correlated queries and
>even temporary table, something I am desperate to avoid
>if possible but not quite cracked it.

Something like this, maybe?

select v.id from vacancy v
join skill s
on s.vacancy_id = v.id
where s.skill = ? /* skill1 */
or s.skill = ? /* skill4 */
or s.skill = ? /* skill8 */
group by 1
having count(v.id) = 3

/heLen