Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7080085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:45:06+00:00 2026-05-28T06:45:06+00:00

Possible Duplicate: Retrieving the last record in each group Hi all i am having

  • 0

Possible Duplicate:
Retrieving the last record in each group

Hi all i am having my table data as follows

ID   FedTaxID  RegularPay  Payperiodnumber

1    562545366   500            1
2    562545366   501            1
3    562545366   5000           2

I would like to get my data as follows

 ID    FedTaxID    RegularPay   Payperiodnumber
 2     562545366     501            1
 3     562545366     5000           2

I tried some thing like as follow but i am not getting the required result

select max(id) ID,regularpay,fedtaxid,payperiodnumber
from tblemployeegrosswagesn1 where fedtaxid="562545366"
group by payperiodnumber
having count(*) >= 1;

Can any one help me

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:45:06+00:00Added an answer on May 28, 2026 at 6:45 am

    This should give you the desired result:

    SELECT      t.ID, 
                t.FedTaxID, 
                t.RegularPay, 
                t.Payperiodnumber
    
    FROM        tblemployeegrosswagesn1 t
    INNER JOIN  (SELECT MAX(ID) AS MaxId, 
                        FedTaxID, 
                        Payperiodnumber 
                 FROM  tblemployeegrosswagesn1  
                 GROUP BY FedTaxID, Payperiodnumber) AS InnerQuery ON t.ID = InnerQuery.MaxId AND t.Payperiodnumber = InnerQuery.Payperiodnumber AND t.FedTaxID = InnerQuery.FedTaxID
    
    WHERE        t.FedTaxID = '562545366';
    

    I am intrigued by the link newtover posted; In this instance, though, you want the max id per payperiodnumber so you’ll have to adapt that a bit more. It will look something like:

    SELECT              t.Id,
                        t.FedTaxId,
                        t.RegularPay,
                        t.Payperiodnumber
    
    FROM                tblemployeegrosswagesn1 t
    
    LEFT JOIN           tblemployeegrosswagesn1 t1  ON (t.FedTaxId = t1.FedTaxId AND t.Payperiodnumber = t1.PayperiodNumber AND t.id < t1.id)   
    
    WHERE               t1.ID IS NULL   
    AND                 t.FedTaxId = '562545366'
    

    Which is much simpler to read. Many thanks to @BillKarwin for a neat set based solution. Thanks for the chance to learn a new (and better given the link posted) way of doing something.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Retrieving the last record in each group I have two tables set
Possible Duplicate: How to replace string in SQLite? I have a table column data
Possible Duplicate: When to use virtual destructors? If all the data members of a
Possible Duplicate: Problem in datareader retrieving data I have Memberships and Bookings tables in
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions
Possible Duplicate: Dynamically retrieving current method's name Obj-C introspection: How can a method reference
Possible Duplicate: Java socket sends some data during connection to server I have two
Possible Duplicate: Retrieving the top 100 numbers from one hundred million of numbers I
Possible Duplicate: Stable way of retrieving the external IP for a host behind a
Possible Duplicate: Retrieving python module path Suppose I have code in 3 python files.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.