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

The Archive Base Latest Questions

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

I have the following Table A & Table B, where A is one to

  • 0

I have the following Table A & Table B, where A is one to many with B; for each record of A, i need to select the corresponding max record on B for each group for A.
i.e. grouping is done based on last_updated_time.

SELECT taba.ws_name, tabb.b2a,  max(tabb.last_update_time)
FROM TabA taba, TabB tabb
where taba.name = 'xyz'
and taba.id = tabb.b2a 
group by taba.ws_name, tabb.b2a 

This works well and fine.

The problem arises when i need to select the “status” as well of the last transaction, this leads to selection of duplicates because status can either be failed or success.

My requirement is to select only the max record irrespective of its status (though i need to display the status as well)

So when ever any “ws_name” has multiple records of failure as well as success so the MAX updated_time gets selected for both groups (of “Failure” & “Success”).

Below is the query which i tried and havent got clue on how to remove the duplicates selected because of status.

SELECT taba.ws_name, tabb.b2a, **tabb.status**,  max(tabb.last_update_time)
FROM TabA taba, TabB tabb
where taba.name = 'xyz'
and taba.id = tabb.b2a 
group by taba.ws_name, tabb.b2a, **tabb.status**
  • 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-28T05:20:46+00:00Added an answer on May 28, 2026 at 5:20 am

    Usually, you need to select the max values, then join onto this result to get the actual values you want.

    For example:

    SELECT     InnerQuery.*,
               TabB.Status
    
    FROM      
                (SELECT     A.ws_name, 
                           B.b2a, 
                           max(B.last_update_time) AS MaxUpdatedTime
    
                FROM       TabA A
                INNER JOIN TabB B ON (A.id = B.b2a)
    
                GROUP BY   A.ws_name,
                                  B.b2a) AS InnerQuery
    INNER JOIN
                TabB ON (InnerQuery.b2a = TabB.b2A AND TabB.last_update_time = InnerQuery.MaxUpdatedTime)
    

    InnerQuery gives you all the rows you want, except without the status. We therefore join back onto B to get the status for the matching rows.

    i.e. we get all the rows in B we want then join back onto B to get the status value for those rows that we’ve uniquely identified, because, as you say, introducing status just gives us another level of grouping.

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

Sidebar

Related Questions

I have 2 tables. One table is 'headings' & contains Headings and the other
I have a table with a one to many mapping to a table that
I have the following table: select * from points +---------+-------------------+------+------+ | NAME | TITLE
I have the following models & mappings (code snippets further below). One Competition has
I am using mysql & perl. I have the following values for one of
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have the following table relationship in my database: Parent / \ Child1 Child2
I have the following table schema; CREATE TABLE `db1`.`sms_queue` ( `Id` INTEGER UNSIGNED NOT
I have the following table structure CREATE TABLE `table` ( `id` int(11) NOT NULL
I have the following table in MySQL (version 5): id int(10) UNSIGNED No auto_increment

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.