Results 1 to 2 of 2

Thread: SQL Query Help

  1. #1
    Join Date
    Aug 2011
    Posts
    1

    SQL Query Help

    Hello Guys,
    This might be a very simple problem but i can't seem to write the query for it.

    I have a table with two columns
    Employee Code - Dept Code
    A - 1
    B - 1

    A - 2
    C - 2

    B - 3
    D - 3

    A - 4
    B - 4
    D - 4

    A - 5
    D - 5

    A - 6
    B - 6
    D - 6
    .....

    now for a list(entered by a user) of Employee Ids say (A,B,D) I need a query (not a stored procedure) to get all the dept codes which have all the three employee ids.
    So above it should return 4 and 6.

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    How about using INTERSECT statement

    SELECT Deptcode
    FROM table
    where employeeid='A'
    INTERSECT
    SELECT Deptcode
    FROM table
    where employeeid='B'
    INTERSECT
    SELECT Deptcode
    FROM table
    where employeeid='D'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •