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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:09:18+00:00 2026-06-18T09:09:18+00:00

I need help on performance of a query I have that is very slow.

  • 0

I need help on performance of a query I have that is very slow.

The query is doing a case on a column in order to return a different text value
based on the number.
If I had a table with values 1-5 and 8-10 If something has a value of 1 it should display ‘Apple’ or if it is 2 it must display ‘pear’ if it is anything other than 1-5 then it is ‘other’. Currently a case statement is being used, but I heard that functions on a query makes it slower.

All I want is the ‘Wording’ to appear instead of the the number but because the table is so big it feels to me like it is iterating each row just to determine what to display.

Is there a faster way of doing this.I considered doing a join, which seems like it would work nice, but I dont know how to write ‘other’ for anything other than 1-5

  • 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-18T09:09:19+00:00Added an answer on June 18, 2026 at 9:09 am

    A case statement is not a function. User-defined functions do have additional overhead in some versions of SQL. You don’t, as a general rule, need to worry about the overhead for built-in functions.

    You could do this with a join as:

    with lookup  as (
         select 1 as val, 'Apple' as str union all
         select 2 as val, 'Pear' as str union all
         select 3 union all select 4 union all select 5
    )
    select coalesce(l.val, 'other')
    from t left outer join
         lookup l
         on t.col = l.val
    

    I would expect the case statement to be marginally faster though.

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

Sidebar

Related Questions

Need help with a query that I wrote: I have three tables Company id
need help/guide for sql select query, I have 2 table stock and stock_history, in
I need to performance tune following SQL query by removing OR statements Please help
Need help regarding performance of a query in PostgreSQL. It seems to relate to
I need help with improving the performance of the following SQL query. The database
need help regarding USSD Gateway. I have to develop an app, which will directly
need help in error in database pivot. i have table tamed table_score like below:
If you have an inefficient query, and you add an index to help out
I need to query a delete statement for the same table based on column
I need some help working out how to make my query more efficient. I'm

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.