Results 1 to 5 of 5
  1. #1
    jkarlos is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2018
    Posts
    2

    Question SQL to return Sales Departments where the sales manager is/isnīt a salesman

    Hi



    I need to build a query where I have 2 tables

    MANAGERS

    DPT_ID | MANAGER

    1 | PERSON_ID1
    2 | PERSON_ID2

    and SALESMEN

    DPT_ID | PERSONID

    1 | PERSON_ID1
    1 | PERSON_ID7
    1 | PERSON_ID8
    2 | PERSON_ID4
    2 | PERSON_ID5
    2 | PERSON_ID6

    and 2 queries to retrieve departments where the manager is and isnīt a salesman in the department.

    For the above data, the first query would return DPT_ID = 1 and for the second DPT_ID = 2

    Thanks

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,409
    you would be better to have one table with an additional field to indicate their role - salesperson or manager. If these are the only two roles and a person can only be a salesperson or a manager this could be done with a Boolean field

    However what about if a person changes roles/departments, leaves etc. You would really need a 'start date' and 'end date' field as well and store their roles in a different table

  3. #3
    jkarlos is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2018
    Posts
    2
    In fact, I have but not in this format, what I have here is

    DPT_ID | MANAGER | SALESMAN

    So, if a Dpt. has 10 salesmen the manager repeats 10 times.

    The approach above was the first proposal to avoid this repetition. To have the role field Iīll have to transform the table first.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,409
    think you need more like

    tblPersons
    personPK
    PersonName


    tblDepts
    DeptPK
    DeptName


    tblRoles
    RolePK
    RoleName


    tblDeployed

    DeployedPK
    PersonFK
    DeptFK
    RoleFK
    StartDate (maybe)
    EndDate (maybe)

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    I agree with Ajax --redesign and normalize. If you are going to use a relational database product, you should abide by some of the basic rules/principles/concepts of relational database.

    Dbms Principles

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 16
    Last Post: 12-28-2017, 02:04 PM
  2. Replies: 26
    Last Post: 11-02-2016, 10:38 AM
  3. Sales/POS problem
    By tyewonk in forum Access
    Replies: 1
    Last Post: 10-13-2013, 07:38 PM
  4. Replies: 0
    Last Post: 12-13-2012, 03:18 AM
  5. Replies: 5
    Last Post: 06-30-2011, 02:24 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums