#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Calgary, Alberta, Canada
    Posts
    52
    Rep Power
    11

    Using exists operator


    I have to use an exists operator to list the course code and title for all courses for which there is someone with qualifications.

    SELECT course.course_code, course.course_title
    FROM DB519S.course
    WHERE exists (SELECT course_code
    FROM DB519S.expertise);

    The code above is returning too many course_codes. What am I doing wrong?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2003
    Location
    Paris Uppland
    Posts
    2,385
    Rep Power
    391
    Code:
    SELECT course.course_code, course.course_title
    FROM DB519S.course
    WHERE course_code in (SELECT course_code
    FROM DB519S.expertise);
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Calgary, Alberta, Canada
    Posts
    52
    Rep Power
    11
    Thanks for the code but the task was to use exists

    I think I got it working

    Code:
    SELECT c.course_code, c.course_title
    FROM DB519S.course c
    WHERE EXISTS (SELECT e.course_code FROM DB519S.expertise WHERE c.employee_id = e.employee_id)
    I know I didn't give the employee_id before but I never thought to use it in the query.

    Thanks for your suggestion though!

IMN logo majestic logo threadwatch logo seochat tools logo