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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:29:35+00:00 2026-06-13T03:29:35+00:00

I have two tables. Table1->Payment AdmissionNum(PK) | StudName | Fees | 1 sagar 5000

  • 0

I have two tables.

Table1->Payment

AdmissionNum(PK)  |  StudName |   Fees |

       1               sagar      5000 
       2               nilesh     6000
       3               amar       4000  

Table2-> paymentDetails

AdmissionNum(FK) | RemainingFees |   Date       |  Payment
        1             4000          1/1/2012          1000
        2             5000          2/5/2012          1000
        1             3500          2/10/2012         1500
        1             2500          2/15/2012         1000
        2             2500          2/20/2012         2500
        3             0             3/25/2012         4000

I have tried different queries but was not able to make joint between payment table and paymentDetails table.
I am making C# windows app. When particular student is paying fees his record is stored in paymentDetails table.
I want to extract only outstanding fees details i.e. student whose Remaining Fees is greater than 0 but the last details in the paymentDetais table i.e. .

My expected resut table is-

AdmissionNum  |  StudName |   Fees | RemainingFees

       1           sagar      5000    2500
       2           nilesh     6000    2500
  • 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-13T03:29:36+00:00Added an answer on June 13, 2026 at 3:29 am

    try this:

    with cte as (select P.AdmissionNum , P.StudName,   P.Fees , D.RemainingFees,row_number() 
    over ( partition by  P.AdmissionNum order by [DATE] desc) as rn
    from Payment P
    join PaymentDetails D
    on P.AdmissionNum=D.AdmissionNum
    where RemainingFees>0)
    select AdmissionNum ,StudName,  Fees , RemainingFees
    from cte
    where rn=1
    

    SQL fiddle demo

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

Sidebar

Related Questions

I have two tables - table1 and table2 table1 has 14 columns and table2
I have two tables table1 and table2 each having a column named email along
I have two tables: table1, table2. Table1 has 10 columns, table2 has 2 columns.
I have two tables (TABLE1, TABLE2 - unique i know) that has a 1-to-many
I have two tables: This is table1: product_id|product_desc|product_name|product_s_desc This is table2: product_price_id|product_id|product_price Now I
I have a scenario like this: There are two tables table1 and table2 .
I have two tables table1 table2 numID|counts|date numID|net|tax|date 1 1 xy 1 2 1
I have two tables table1: { id, name } table2: { id, table1_id, time_added
I have two tables table1 and table2 . Both tables have the same structure.
I have two tables table1 , table2 . Both have a one to one

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.