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

The Archive Base Latest Questions

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

Im currently working on troubleshooting an old job which is taking long in running

  • 0

Im currently working on troubleshooting an old job which is taking long in running the query. The old job uses the first query but I have been testing using the second query.

Differences between:

Select Max(Cl1) as Tab,
       Max(Cl2) as Tb,
       Customer
From TableA
group by Customer

vs

Select Customer,
       Tab,
       tb
From 
(Select Customer,
         Tab,
         tb,
         Rank() over (partition by Customer order by Cl1 desc) rk1,
         Rank() over (partition by Customer order by Cl2 desc) rk2
  From TableA) X
 Where X.rk1 = 1 and X.rk2 = 1

Tab Tb Customer

A45845 100052 Shin

A45845 100053 Shin

A45845 100054 Reek

The table will always have value (no nulls or blank value) for both Tab and Tb columns. Tab is not unique to a particular customer. Tb is a sequential and continuously increasing integer with no duplicates possible (unique). The latest Tab value for a customer will also have the most recent Tb as well.

Though the results are the same, is there something I may not be considering when changing the query in this case?

Edit: Fixed errors on second query when building example and not using real column or table names. Also explanded on scenario. My apologies about the updated info and fix in original post, was called before I even had a chance to double check it.

  • 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-17T10:02:13+00:00Added an answer on June 17, 2026 at 10:02 am

    This would be the equiv query, but I doubt it would be more efficient. @Damien_The_Unbeliever please let me know if I’m wrong again. (Distinct added for the scenario where there are multiple Cl1 and Cl2 rows with the same value. This can be removed if the primary key is across customer, Cl1 and Cl2.)

    Select  Distinct Customer,
            X.Cl1 as Tab,
            X2.Cl2 as tb
    From   (Select  Customer,
                    Rank() over (partition by Customer order by Cl1 desc) rk1, 
                    Cl1
            From    TableA) X
    Join   (Select  Customer,         
                    Rank() over (partition by Customer order by Cl2 desc) rk2, 
                    Cl2
            From    TableA) X2
            On  X.Customer = X2.Customer
    Where   X.rk1 = 1 
    And     X2.rk2 = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently working on something which uses ajax for some pagination. What I'm looking to
Im currently working on a project which uses jqGrid with multiple subgrids. I'm trying
I currently have a database call which works in one area, but not another.
Currently working for the first time with JSON and with little experience of jQuery.
Im currently working on a game that uses multi touch to apply zoom to
We have an old application that was written in Delphi 7. It is currently
Okay, I have been working for quite some time on a website for a
Im currently working on a site which will contain a products catalog. I am
Currently working with Oracle, but will also need a solution for MS SQL. I
I'm working on my first android app and have an SQLite database set up

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.