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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:52:35+00:00 2026-06-10T03:52:35+00:00

Can we use Order By clause when we are using Select Query in Select

  • 0

Can we use Order By clause when we are using Select Query in Select List ?

I want to write query like this :-

select col1
     , col2
     , (select colX from table2 where table2.col1=table1.col1 and rownum<2 order by colY desc) 
     , (select colXX from table3 where table3.col1=table1.col1 and rownum<2 order by colYY desc)
from table1;

I can’t join the table. Its just example of what I want.

OK. Here is the thing.
I have following code written in SQL Server . I want to convert it into Oracle.

SELECT
BANK_ADDRESS1= (SELECT top 1 OWNER_ADDRESS1 
            FROM OWNER_ADDRESS OA, BANK_ACCOUNT
            WHERE PAYMENT.BANK_ACCOUNT_ID = BANK_ACCOUNT.BANK_ACCOUNT_ID
                    and BANK_ACCOUNT.BANK_ID = OA.OWNER_ID
                    order by Isnull (OA.primary_addr , 'N') desc),
PAYEE_ADD1 = (  SELECT top 1 OWNER_ADDRESS1 
                FROM OWNER_ADDRESS OA 
                WHERE OA.OWNER_ID = PAYEE_OWNER.OWNER_ID 
                order by Isnull (OA.primary_addr , 'N') desc ),
FROM    PAYMENT 
            inner JOIN PAYEE ON PAYMENT.PAYMENT_ID = PAYEE.PAYMENT_ID
            inner join OWNER PAYEE_OWNER on PAYEE_OWNER.OWNER_ID = PAYEE.PAYEE_NAME_ID

Hope this will clear what I really want.

  • 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-10T03:52:37+00:00Added an answer on June 10, 2026 at 3:52 am

    You want something like this:

    select col1,
           col2,
           (select colX
              from (select col1, colX from table2 order by colY desc) table2
             where table2.col1 = table1.col1
               and rownum < 2),
           (select colXX
              from (select col1, colXX from table3 order by colYY desc) table3
             where table3.col1 = table1.col1
               and rownum < 2)
      from table1;
    

    or this:

    select col1,
           col2,
           (select max(colX) keep(dense_rank last order by colY)
              from table2
             where table2.col1 = table1.col1),
           (select max(colXX) keep(dense_rank last order by colYY)
              from table2
             where table2.col1 = table1.col1)
      from table1;
    

    This subselect

    (select colX from table2 where table2.col1=table1.col1 and rownum<2 order by colY desc)
    

    even if it worked would not return what you expect because rownum is calculated before order by. You would get random row from those which fulfill the condition table2.col1 = table1.col1 .

    Try

    select (SELECT max(OWNER_ADDRESS1) keep(dense_rank last order by nvl(oa.primary_addr, 'N'))
              FROM OWNER_ADDRESS OA, BANK_ACCOUNT
             WHERE PAYMENT.BANK_ACCOUNT_ID = BANK_ACCOUNT.BANK_ACCOUNT_ID
               and BANK_ACCOUNT.BANK_ID = OA.OWNER_ID) bank_address1,
           (SELECT max(OWNER_ADDRESS1) keep(dense_rank last order by nvl(oa.primary_addr, 'N'))
              FROM OWNER_ADDRESS OA
             WHERE OA.OWNER_ID = PAYEE_OWNER.OWNER_ID) payee_add1
      from PAYMENT
     inner JOIN PAYEE
        ON PAYMENT.PAYMENT_ID = PAYEE.PAYMENT_ID
     inner join OWNER PAYEE_OWNER
        on PAYEE_OWNER.OWNER_ID = PAYEE.PAYEE_NAME_ID
    

    (I could have made some syntax errors, cannot check it).

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

Sidebar

Related Questions

I don't think that I can use ORDER BY clause inside the GROUP_CONCAT function.
I would like to know what solution I can use in order to have
Problem I am using alternate column name (alias) in a Query, I can use
In PostgreSQL, there is this very useful string_agg function, that allows query like: SELECT
If we use the Limit clause in a query which also has ORDER BY
I have a date column and I am using order by clause. I want
I need to order a select query using a varchar column, using numerical and
I can use the MS Word ActiveX control in order to access some parameters
XmlElement has an Order attribute which you can use to specify the precise order
in order to avoid copy/paste, i can use a unique view for different actions,

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.