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

The Archive Base Latest Questions

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

I am using the following MySQL query which is working fine, I mean giving

  • 0

I am using the following MySQL query which is working fine, I mean giving me the desired output but… lets first see the query:

select 
    fl.file_ID,
    length(fl.filedesc) as l,
    case 
        when 
            fl.part_no is null
            and l>60
            then concat(fl.fileno,' ', left(fl.filedesc, 60),'...')
        when
            fl.part_no is null
            and length(fl.filedesc)<=60
            then concat(fl.fileno,' ',fl.filedesc)
        when
            fl.part_no is not null
            and length(fl.filedesc)>60
            then concat(fl.fileno,'(',fl.part_no,')', left(fl.filedesc, 60),'...')      
        when
            fl.part_no is not null
            and length(fl.filedesc)<=60
            then concat(fl.fileno,'(',fl.part_no,')',fl.filedesc)
        end as filedesc
from filelist fl

I don’t want to use the length function repeatedly because I guess it would hit the database everytime claiming performance issue. Please suggest if I can store the length once and use it several times.

  • 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-26T16:08:53+00:00Added an answer on May 26, 2026 at 4:08 pm

    Once you have accessed a given row, what you do with the columns has only a small impact on performance. So your guess that it “hits the database” more to serve repeated use of that length function isn’t as bad as you think.

    The analogy I would use is a postal carrier delivering mail to your house, which is miles outside of town. He drives for 20 minutes to your mailbox, and then he worries that it takes too much time to insert one letter at a time into your mailbox, instead of all the letters at once. The cost of that inefficiency is insignificant compared to the long drive.

    That said, you can make the query more concise or easier to code or to look at. But this probably won’t have a big benefit for performance.

    select 
        fl.file_ID,
        concat(fl.fileno,
               ifnull(concat('(',fl.part_no,')'), ' '),
               left(fl.filedesc,60),
               if(length(fl.filedesc)>60,'...','')
        ) as filedesc
    from filelist fl
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using following code but cannot return data from MySQL. This is the output:
Using MySQL syntax, how would I write a query to return the following (I
Currently I using the following code to get my JSON output from MySQL. <?php
I have the following MySQL query, which produces the result I want: SELECT `l`.`status`,
I have the following query (which should return a scalar/numeric), But I still get
I have written an application using Seam 2.2.1 & MySQL which is working. I
I am working on to build a query in MYSQL by which I can
I am using the following InnoDB tables in mysql to describe records that can
I am using a MySQL table called login with the following structure: loginid, username,
I'm using MySQL API's function mysql_real_escape_string() Based on the documentation, it escapes the following

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.