Results 1 to 14 of 14
  1. #1
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105

    Dduplicates in query

    Hi colleagues,
    I have a table with weekly wages. I would like to extract the data which would indicate when persons received a raise. These are the fields I have in the query.
    Begin Date Hourly Wage Soc Security Number Employee Name
    I want data for the original rate at time of hire and the first date each new rate was used. So I would want eg data for begin date Nov 4 and Nov 25.

    Begin Date Hourly Wage Soc Security Number Employee Name
    04-Nov-18 $15.00 000001111 Robert Williams
    11-Nov-18 $15.00 000001111 Robert Williams
    25-Nov-18 $18.00 000001111 Robert Williams
    02-Dec-18 $18.00 000001111 Robert Williams

    Thanks for your assistance

    Cristina


  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    So you want the earliest record for each Employee/Wage pair. This will probably need a nested query using TOP 1. Review http://allenbrowne.com/subquery-01.html#TopN

    Need a unique identifier field - autonumber type will serve.

    SELECT Table1.* FROM Table1 WHERE ID IN (SELECT TOP 1 ID FROM Table1 AS Dupe WHERE Dupe.EmployeeName=Table1.EmployeeName AND Dupe.HourlyWage=Table1.HourlyWage ORDER BY Dupe.EmployeeName, Dupe.BeginDate);

    Be aware this sort of nested query can perform slowly with very large dataset.
    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
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105

    SELECT DISTINCT [Salary Register].[Hourly Wage], [Salary Register].[Social Security Number], [Employee Records]![First Name] & " " & [Employee Records]![Last Name] AS [Employee Name], [Salary Register].[Begin Date]
    FROM [Employee Records] RIGHT JOIN [Salary Register] ON [Employee Records].[Social Security Number] = [Salary Register].[Social Security Number];

    Thanks

  4. #4
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    I do not see my entire message. I was asking for your assistance, as I am not versed with SQL. I copied the SQL from the query I made.

    Would you be able to assist me with the additional codes needed.

    Thanks
    Cristina

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Apparently I edited my previous post after you read it. Review again.
    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.

  6. #6
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    This is my trial

    SELECT DISTINCT [Salary Register].[Hourly Wage], [Salary Register].[Social Security Number], [Employee Records]![First Name] & " " & [Employee Records]![Last Name] AS [Employee Name], [Salary Register].[Begin Date]
    FROM [Employee Records] RIGHT JOIN [Salary Register] ON [Employee Records].[Social Security Number] = [Salary Register].[Social Security Number];
    WHERE Salaries Register.Hourly Wage
    (SELECT TOP 1 Hourly Wage
    FROM Salaries Register AS Dupe
    WHERE Dupe.Hourly Wage = Rate
    ORDER BY Dupe.Salaries Register, Dupe.OrderID DESC)
    ORDER BY Salaries Register.Name, Salaries Register.Begin Date, Salaries Register.Hourly Wage;

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    That's not following my suggested syntax. I doubt OrderID is a field in your table.

    Are you saving SSN into Salary Register table? Why? This should only be in Employee Records table. Should not use SSN as PK/FK. Use an autonumber field or an EmployeeNumber you create.

    Advise not to use spaces in naming convention.
    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.

  8. #8
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    Hello June7....Grateful for your assistance
    I tried the code, but it gives a message. See below. I take note of your suggestions especialy about the SSN Reason I have it is I have a main form Employee records, and a subform Salaries Register to enter salaries. I have linked fields of SSN and wage rate.
    SELECT Salaries Register.* FROM Salaries Register WHERE ID IN (SELECT TOP 1 ID FROM Salaries Register AS Dupe WHERE Dupe.EmployeeName=Salaries Register.EmployeeName AND Dupe.HourlyWage=Salaries Register.HourlyWage ORDER BY Dupe.EmployeeName, Dupe.BeginDate);

  9. #9
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    I do have an auto number field camed ID.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Not seeing error message in your post.
    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.

  11. #11
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105

  12. #12
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    Syntax error in query expression 'ID IN (SELECT TOP 1 ID FROM Salaries Register AS Dupe WHERE Dupe.EmployeeName=Salaries
    Register.EmployeeName AND Dupe.HourlyWage=Salaries Register.Hourly Wage ORDER BY Dupe.EmployeeName,


    Please see error msg

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Error message still not showing in post. Is it an image? Maybe my computer/browser has issue. Happens sometimes with embedded images in post.

    You have spaces in names. Need to enclose in [ ]: [Salaries Register]

    Advise not to use spaces in naming convention.
    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.

  14. #14
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    I have decided to close this. I did a report and sorted and grouped and was able to get the desired result. Thanks for your assistance. Regards

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

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