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

  • Home
  • SEARCH
  • 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 8620751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:39:17+00:00 2026-06-12T06:39:17+00:00

This is master table Query Select * from AC_TAB where AC_ID = 7 ;

  • 0

This is master table Query

Select * 
from AC_TAB 
where AC_ID = 7 ; 

AC_PK AC_ID TYPE  STATUS   INS_DATE               VALID
102   7     0     0        3/21/2012 3:35:08 PM   0 
103   7     1     0        3/21/2012 3:35:08 PM 
104   7     2     1        3/21/2012 3:35:08 PM 

I am joining this table with txn table using ac_id. Since here its having 3 rows for ac_id 7 , my txn table returning 3 times. how to restrict this. since i want to return only one irrespective of type

MY Txn Query

Select txn_id, amount 
from txn_hdr , ac_tab 
where txn_ac_id = ac_id ;

txn_id  amount   
 1       200 
 1       200 
 3       100 
 3       100 
  • 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-12T06:39:18+00:00Added an answer on June 12, 2026 at 6:39 am

    It is not actually clear what you need but it sounds like you only want to return one record per ac_id from the AC_TAB. If so, then there are a few ways that you can do this.

    Using a subquery:

    select *
    from
    (
      select max(INS_DATE) INS_DATE, AC_ID
      from ac_tab
      group by AC_ID
    ) a
    inner join txn_hdr t
      on a.ac_id = t.ac_id;
    

    Or with CTE using a row_number():

    ;with cte as
    (
      select a.ins_date, a.ac_id, t.amount, row_number() 
                over(partition by a.ac_id order by a.ins_date desc) rn
      from ac_tab a
      inner join txn_hdr t
        on a.ac_id = t.ac_id
    )
    select *
    from cte 
    where rn = 1;
    

    Or with a row_number() in a subquery:

    select *
    from 
    (
      select a.ins_date, a.ac_id, t.amount, row_number() 
                over(partition by a.ac_id order by a.ins_date desc) rn
      from ac_tab a
      inner join txn_hdr t
        on a.ac_id = t.ac_id
    ) x
    where rn = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this SELECT name FROM sqlite_master WHERE type = table AND name
Is there a way this hand coded query could become dynamic? SELECT master.id, (select
If I get records from my SQLite database's master table like this: $database =
I am trying to create a delete query to remove records from one table,
This is more a conceptual question. It's inspired from using some extremely large table
I am using Oracle 10g. Here is my query select * from Entries where
This is the master table structure: CREATE TABLE IF NOT EXISTS `gf_film` ( `film_id`
I've got two legacy database tables, layouted in simplified manner like this: MASTER SLAVE
my structure is like this: master page aspx(web form) ascx(user control) I have a
So I applied this master page to two files..one inside the same folder(file1.aspx) as

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.