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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:01:38+00:00 2026-06-17T08:01:38+00:00

I have a table XYZ as +——+——+——+—–+ | X1 | x2 | x3 |

  • 0

I have a table XYZ as

+------+------+------+-----+
|  X1  |  x2  |  x3  |  x4 |
+------+------+------+-----+
|  a   |   b  |  c   |  1  |
|  a   |   b  |  d   |  2  |
|  p   |   q  |  e   |  3  |
|  p   |   q  |  f   |  4  |
+------+------+------+-----+

condition is if x1 and x2 matches then get x3 and x4 of
row where x4 is maximum
when i will query this table I want to get output as

+------+------+------+-----+
|  X1  |  x2  |  x3  |  x4 |
+------+------+------+-----+
|  a   |   b  |  d   |  2  |
|  p   |   q  |  f   |  4  |
+------+------+------+-----+

i tried as
select * from XYZ t1,
(select x1,x2,max(x4) from XYZ ) t2
where t1.x1=t2.x1 and t1.x2=t2.x2

but i want to use advance functions like rank and partations
as this is much slow in large database

  • 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-17T08:01:39+00:00Added an answer on June 17, 2026 at 8:01 am

    rank or row_number can be used depending on whether you want to return multiple rows in the case of x4 being equal.

    eg:

    SQL> select *
      2    from (select x1, x2, x3, x4, rank() over (partition by x1, x2 order by x4 desc) rnk
      3            from xyz)
      4   where rnk = 1;
    
    X X X         X4        RNK
    - - - ---------- ----------
    a b d          2          1
    p q f          4          1
    

    but if for a, b we had two rows at x4=2, then we’d get two rows back:

    SQL> insert into xyz values ('a', 'b', 'd', 2);
    
    1 row created.
    
    SQL> select *
      2    from (select x1, x2, x3, x4, rank() over (partition by x1, x2 order by x4 desc) rnk
      3            from xyz)
      4   where rnk = 1;
    
    X X X         X4        RNK
    - - - ---------- ----------
    a b d          2          1
    a b d          2          1
    p q f          4          1
    

    if you wanted just one, use row_number() instead:

    SQL> select *
      2    from (select x1, x2, x3, x4, row_number() over (partition by x1, x2 order by x4 desc) rn
      3            from xyz)
      4   where rn = 1;
    
    X X X         X4         RN
    - - - ---------- ----------
    a b d          2          1
    p q f          4          1
    
    SQL>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table with 300 000 records (MyISAM). I get record from this table
Is there something simiar? I have this definition create table xyz ( fecha_alta timestamp
I have a table like this column1 column2 column3 abc xyz 4 def ghi
I am having trouble trying to get this query right. Say I have a
I have a table like this: id products_name sort 1 abc 0 2 xyz
I have a table in db2 which has the following fields int xyz; string
I have table and this table contain result column with some entries. I just
I have table View with grouped style with three sections. Get information from dictionary
I have a table student like this id | name | zip 1 |
I have a table like this: id | name | class | marks 1

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.