简体   繁体   中英

SQL SEARCHING relational database

given a users qualification id's how would you find the jobs they can do using SQL?

1) for example a user with only qualification 1 could only do job3 and not 1 and 4 because you need more than one qualification. 2) a user with qualifications 1 and 2 could do jobs 1 and 3 but not 4

JOBDETAILS TABLE

JobID ,QualificationID

1, 1

1, 2

3, 1

4, 1

4, 2

4, 3

thanks for any help

TJ

SELECT DISTINCT JobID
FROM JobDetails
WHERE QualificationID IN (@Quals)
AND JobID NOT IN
(
  SELECT DISTINCT JobID
  FROM JobDetails
  WHERE QualificationID NOT IN (@Quals)
) 

(Apologies for syntax issues; I work with SQL Server, not MySQL)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM