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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:25:53+00:00 2026-05-26T08:25:53+00:00

I have written the following query: SELECT CLIENT.CLIENTNO, CLIENT.CNAME, TOTALS.TOTAL FROM CLIENT, (SELECT CLIENTNO,

  • 0

I have written the following query:

SELECT CLIENT.CLIENTNO, CLIENT.CNAME, TOTALS.TOTAL 
FROM CLIENT, (SELECT CLIENTNO, SUM(AMOUNT) AS TOTAL 
              FROM PURCHASE GROUP BY CLIENTNO) TOTALS 
WHERE CLIENT.CLIENTNO = TOTALS.CLIENTNO AND ROWNUM <= 1 
ORDER BY TOTALS.TOTAL DESC;

However it is giving me the wrong answer, but if I remove the ROWNUM <= 1 clause, then the correct answer is at the top of the result set.

So what can I change in this query to make it produce the correct answer?

Thanks,
Alex.

EDIT: Forgot to say that I only want the query to return the the first result in the result set.

  • 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-26T08:25:54+00:00Added an answer on May 26, 2026 at 8:25 am

    The ROWNUM filter applies before the sorting. What you need to do is this:

    SELECT * FROM (
      SELECT CLIENT.CLIENTNO, CLIENT.CNAME, TOTALS.TOTAL 
      FROM CLIENT, (SELECT CLIENTNO, SUM(AMOUNT) AS TOTAL 
                      FROM PURCHASE GROUP BY CLIENTNO) TOTALS 
      WHERE CLIENT.CLIENTNO = TOTALS.CLIENTNO 
      ORDER BY TOTALS.TOTAL DESC
    )
    WHERE ROWNUM <= 1 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following query. select distinct(table3.*), (select count(*) from table2 where table2.cus_id
I have the following Query: SELECT * FROM tbl_Muffins WHERE OvenLoadId IN ( SELECT
I have following query written in HQL for Hibernate. ======================================================================== select new map(ret.retailerDesc as
I have the following query sql query: select * from Articles ar left join
I have the following MySql query: select t1.* from Table1 t1 inner join Table2
I have written a DB2 query to do the following: Create a temp table
I have written the following query using the documentation at: Oracle Documentation to copy
I have written the select fallowing query but it is giving different results surprisingly
i have written the following query and it is giving error Unable to cast
I am very new in LINQ I have written following query : var duplicate

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.