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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:53:57+00:00 2026-05-13T22:53:57+00:00

I have to sort out my data by some column, such that some specific

  • 0

I have to sort out my data by some column, such that some specific value appears first. So for a query like this …

  SELECT rtrim(taskid) into v_taskid FROM tasks
  where
    /* some where clausers */
  and rownum = 1

… I have based it on case when, but what bothers me is three nested selects I have now:

  SELECT rtrim(taskid) into v_taskid FROM tasks where taskid in (
    select taskid from (
        select taskid,
        case when taskuser like '%myuser%' 
       then 0
           else 100
        end as ordervalue
        FROM tasks
        where       
          /* some where clausers */
        order by ordervalue
        )
    )    
    and rownum = 1

Performance-wise I think it shouldn’t be a problem, but it looks kind of a spaghetti… Is there any way to put case-when into the where clause?

  • 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-13T22:53:57+00:00Added an answer on May 13, 2026 at 10:53 pm

    You are querying the tasks table twice. This is not needed and will make your query run slowly. Your query can be combined into a simple query like so:

    SELECT rtrim(taskid) into v_taskid
    FROM (
      SELECT taskid 
      FROM tasks 
      WHERE /* some where clauses */
      ORDER BY case when taskuser like '%myuser%' then 0 else 100 end
    )
    WHERE rownum = 1;
    

    Then either just retrieve the first row or add the rownum part in an outer query.

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

Sidebar

Related Questions

I have some data coming out of an DB that I can't readily change
I am just facing trouble to sort out the query I need. I have
I have some issues with number <-> string conversion i cannot sort out. We
I have a table like this: | X | Y | Data | ----------------
I have the code as per below. This retrieves some data to use for
I have some Data coming out of my DB Model. What I want to
I have a simple question, not able to sort it out. I have a
I have sort of a tricky problem I'm attempting to solve. First of all,
I have some sort of problem, when it comes to customizing the iPad-launch-lcreens of
I have some sort of recursive function, but I need to parse a string,

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.