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 8038073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:07:04+00:00 2026-06-05T03:07:04+00:00

I have a table called tblAccInfo, below is the table data. I need output

  • 0

I have a table called tblAccInfo, below is the table data.
I need output like below.

Input
PolicyNumber    BankAc   StorageDate    VerNum
6003210400      123      2012-01-01     1
6003210400      164      2012-01-03     2
6003210400      860      2012-01-05     3
6004317654      301      2012-02-05     1
6004317654      615      2012-03-01     2
6004317654      253      2012-03-12     3
6004317654      887      2012-04-03     4

OUTPUT

PolicyNumber  IntialBankAc IntialSDate VerNum  LatestBankAc LatestSDate VerNum
6003210400    123          2012-01-01  1       860          2012-01-05  3
6004317654    301          2012-02-05  1       887          2012-04-03  4

I have tried with below self join, but did not succeeded. Please help me out in this.

Select DISTINCT
    P.PolicyNumber,
    P.BankAc [IntialBankAc],
    P.StorageDate IntialSDate],
    P.VerNum,
    P1.BankAc [LatestBankAc],
    P1.StorageDate [LatestSDate],
    P1.VerNum
FROM tblAccInfo P
INNER JOIN tblAccInfo P1
ON P1.PolicyNumber=P.PolicyNumber
AND (P.BankAc<>P1.BankAc AND P.StorageDate<>P1.StorageDate AND P.VerNum<>P1.VerNum)
  • 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-06-05T03:07:06+00:00Added an answer on June 5, 2026 at 3:07 am

    Try this:

    SELECT
        T1.PolicyNumber,
        T2.BankAc AS IntialBankAc,
        T2.StorageDate AS IntialSDate,
        T2.VerNum AS InitalVerNum,
        T3.BankAc AS LatestBankAc,
        T3.StorageDate AS LatestSDate,
        T3.Vernum AS LatestVerNum
    FROM
    (
        SELECT
            PolicyNumber,
            MIN(VerNum) AS MinVerNum,
            MAX(VerNum) AS MaxVerNum
        FROM tblAccInfo
        GROUP BY PolicyNumber
    ) AS T1
    JOIN tblAccInfo AS T2
    ON T1.PolicyNumber = T2.PolicyNumber
    AND T1.MinVerNum = T2.VerNum
    JOIN tblAccInfo AS T3
    ON T1.PolicyNumber = T3.PolicyNumber
    AND T1.MaxVerNum = T3.VerNum
    

    See it working online: sqlfiddle

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

Sidebar

Related Questions

I have table called Data_Details and the data looks like: DateTimeClosed Datesub TimeSub 6/20/2011
i have table called table1 and it looks like the below record type tran_ref_number
I have table called Direccion other called Cliente each one defined like this public
I have a table called person, one of the attributes is years_worked. I need
i have table called type which contains data family,individual i want in some pages
I have a table called users where the employee data are stored. Also I
I have a table called reports it looks like: user_id | report_post 1 2
I have table called 'shipped_data' https://i.stack.imgur.com/JXBej.png and need go get all 'caseNumbers' that match
hi i have table called products with columns product_id prodcut_name prodcut_price( values like 1200,2000,3000,100)
I have a table called 'MyTable' that looks like: ID | Item | Type

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.