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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:22:41+00:00 2026-06-04T13:22:41+00:00

I am normally using MS SQL and am a total rookie with oracle. I

  • 0

I am normally using MS SQL and am a total rookie with oracle.

I get an oracle driver problem when I use the ORDER BY statement in my subquery.

Example (my real statement is much more complex but I doubt it matters to my problem – I can post it if needed):

SELECT col1
     , col2
     , (SELECT colsub FROM subtbl WHERE idsub = tbl.id AND ROWNUM=1 ORDER BY coldate) col3
FROM tbl

If I do such a construct I get an odbc driver error: ORA-00907: Right bracket is missing (translated from german, so bracket might be other word :)).

If I remove the ORDER BY coldate everything works fine. I couldn’t find any reason why, so what do I wrong?

  • 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-04T13:22:43+00:00Added an answer on June 4, 2026 at 1:22 pm

    It doesn’t make any sense to write the ROWNUM and the ORDER BY this way since the ORDER BY is evaluated after the WHERE clause, meaning that it has no effect in this case. An example is given in this question.

    This also gets a little more complicated because it is hard to join a sub-query back to the main query if it is nested too deeply.

    The query below won’t necessarily work because you can’t join between tbl and subtbl in this way.

    SELECT 
      col1,
      col2,
      (
        select colsub
        from  (
          SELECT colsub 
           FROM subtbl 
           WHERE idsub = tbl.id
           order by coldate
        )
        where rownum = 1
      ) as col3
    FROM tbl
    

    So you’ll need to use some sort of analytic function as shown in the example below:

    SELECT 
      col1,
      col2,
      (SELECT max(colsub) keep (dense_rank first order by coldate) as colsub
       FROM subtbl 
       WHERE idsub = tbl.id
       group by idsub
    ) col3
    FROM tbl
    

    The FIRST analytic function is more complicated than it needs to be but it will get the job done.

    Another option would be to use the ROW_NUMBER analytic function which would also solve the problem.

    SELECT 
      col1,
      col2,
      (select colsub
       from (
         SELECT 
           idsub, 
           row_number() over (partition by idsub order by coldate) as rown,
           colsub
       FROM subtbl a 
       ) a
       WHERE a.idsub = tbl.id
       and a.rown = 1
    ) col3
    FROM tbl
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Normally we all do use using System.Linq; and using System.Data.Linq; for example on the
I'm considering using LINQ-to-SQL for creating the DAL in my app. I normally create
Using LINQ or SQL, how could I have the following strings, normally sorted as:
I created a user on the SQL Server but using that login I get
I'm using SQL Server 2008 and just recently started having an intermittent problem while
I'm currently building an application using entity framework. Normally I would use a stored
Normally when using Lucene you set a search query and Lucene gives you some
First post here... I normally develop using PHP and Symfony with Propel and ActionScript
Normally, when using the XMLSerializer to automagically serialize an ISerializable object, a .dll file
I normally code on windows and using MYSQL4.1. And mysql gem version is 2.8.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.