Results 1 to 4 of 4
  1. #1
    Eric Huang is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    1

    Question with query

    Hi,

    I am fairly new to Access, and I hope someone here can help me with my question.

    I am trying to combine two tables with different fields. My first table has salary data of each employee:

    Event ID (primary key)
    Employee ID
    Event type (pay raise or pay decrease)
    Event date
    New salary figure

    Second table has injury data:

    Event ID (primary key)
    Employee ID
    Event type (type of injury)
    Event date
    + other fields related to the injury



    I tried to create a query that display all events and event details related to an employee in chronological order, but I ended up getting the permutation of the two tables. What would be the proper way of doing this?

    Also, for logistic reason, I prefer not to create a combined table that has all the above fields.

    Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Try a UNION query. There is no wizard or designer for UNION query. Must type in the SQL View editor window.

    SELECT "PayChange" As Source, EmployeeID, EventID, EventDate, EventType, Salary FROM Table1
    UNON
    SELECT "Injury", EmployeeID, EventID, EventDate, EventType, Null FROM Table2

    If field names do have space, enclose names in []. Advise to not use spaces in any names.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Access_Blaster is offline User
    Windows XP Access 2010 32bit
    Join Date
    May 2010
    Posts
    339
    Quote Originally Posted by Eric Huang View Post
    Hi,

    I am fairly new to Access, and I hope someone here can help me with my question.

    I am trying to combine two tables with different fields. My first table has salary data of each employee:

    Event ID (primary key)
    Employee ID
    Event type (pay raise or pay decrease)
    Event date
    New salary figure

    Second table has injury data:

    Event ID (primary key)
    Employee ID
    Event type (type of injury)
    Event date
    + other fields related to the injury

    I tried to create a query that display all events and event details related to an employee in chronological order, but I ended up getting the permutation of the two tables. What would be the proper way of doing this?

    Also, for logistic reason, I prefer not to create a combined table that has all the above fields.

    Thanks
    Why does table (2) have the same field names as table (1)? Are you duplicating information? You could have..

    Employee table
    EmployeeID (primary key)
    EfirstName
    ElastName
    Etc..

    Event table
    EventID (primary key)
    EmployeeID (foreign key)
    EventType
    EventDate
    Etc...

    Salary table?
    SalaryID (primary key)
    Etc..

    Then you could link with the EmployeeID's or some other unique field.
    Richard

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Please describe your tables in plain English. Why is EventId PK on the 2 tables? I think normalization of tables may be an issue. Getting you tables and relationships designed is basic to ease of use and stability.

    What is an Event?

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

Similar Threads

  1. Query question/help
    By 9944pdx in forum Queries
    Replies: 4
    Last Post: 12-12-2017, 08:13 PM
  2. Query question
    By j2curtis64 in forum Queries
    Replies: 8
    Last Post: 07-29-2011, 01:45 PM
  3. Query Question
    By starhannes in forum Queries
    Replies: 13
    Last Post: 05-06-2010, 04:05 PM
  4. Query with a question
    By sagit3 in forum Queries
    Replies: 0
    Last Post: 06-11-2009, 07:10 AM
  5. Query Question
    By blewis in forum Queries
    Replies: 0
    Last Post: 04-16-2009, 01:37 PM

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