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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:30:52+00:00 2026-05-22T21:30:52+00:00

I wrote a query that my db admins are telling me need optimized, but

  • 0

I wrote a query that my db admins are telling me need optimized, but my SQL knowledge is limited. The query pulls the press releases and 1 related photo and caption for each. It joins the site (location) table on id.

<cfquery name="local.query" datasource="#this.Dsn()#">
            SELECT
            pr.press_release_id,
            pr.Site_id,
            pr.press_release_subject,
            pr.press_release_title,
            pr.press_release_datetime,
            pr.press_release_number,
            pr.press_release_published_flag,
            pr.press_release_top_story,
            pr.related_photo_gallery,
            pr.related_page,
            s.site_name,
            (SELECT TOP 1 ph.press_release_photo_lowres_filename
                FROM
                    tbl_photo as ph
                WHERE
                    ph.press_release_id = pr.press_release_id) as photo_filename,
            (SELECT TOP 1 ph.press_release_photo_caption
                FROM
                    tbl_photo as ph
                WHERE
                    ph.press_release_id = pr.press_release_id) as photo_caption
            FROM
            tbl_press_release as pr

            INNER JOIN tbl_site s 
                ON pr.Site_id = s.site_id
            WHERE
                LEFT(pr.press_release_number,1) <> <cfqueryparam cfsqltype="cf_sql_varchar" value="I">
                <cfif val(event.GetValue("site_id")) gt 0>
                     AND s.site_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#val(event.GetValue("site_id"))#">
                 </cfif>
            <cfif event.GetValue("pao_search") neq "">
            AND
            (
                press_release_subject like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#event.GetValue("pao_search")#%">
                OR
                press_release_copy like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#event.GetValue("pao_search")#%">
                OR
                press_release_wingspan_title like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#event.GetValue("pao_search")#%">
                OR
                press_release_wingspan_subject like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#event.GetValue("pao_search")#%">
            )
            </cfif>
            AND pr.press_release_published_flag = <cfqueryparam cfsqltype="cf_sql_integer" value="1">
            AND (pr.press_release_top_story <> <cfqueryparam cfsqltype="cf_sql_bit" value="True"> OR pr.press_release_top_story IS NULL)
        <cfif listLen(event.GetValue("orderBy")) neq 0>

        ORDER BY
            <cfloop list="#event.GetValue("orderBy")#" index="local.o">#local.o# #uCase(event.GetValue("sort"))#<cfif local.o neq listLast(event.GetValue("orderBy"))>,</cfif></cfloop>
        </cfif>
        </cfquery>

From what the admins told me, the embedded SELECT statements are slowing the query down. I realize now that pulling associated images and captions for every press release is unnecessary since I only need to pull them for press releases with press_release_top_story that equals true. I think that might help save some CPU as well.

What can I do to optimize this? FYI this is for SQL Server is that matters.

  • 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-22T21:30:52+00:00Added an answer on May 22, 2026 at 9:30 pm

    First and foremost, consider caching. ColdFusion can easily cache queries (e.g. <cfquery cachedWithin="#createTimeSpan(d, h, m, s)#">...</cfquery>, but if you need to ensure timeliness when the underlying press release table updates, instead use cachePut() and cacheGet(), where values are put in when the press release table is updated.

    Next, the WHERE clause LIKE statements are probably the culprit for the slowdown: two approaches to consider are a SQL Server full text index or using ColdFusion’s search capabilities. In addition, use SQL Server’s database tuning advisor on the query to see if there are other indices that will improve performance.

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

Sidebar

Related Questions

I wrote a query that works like a charm in SQL Server. Unfortunately it
Hi i've wrote a query that works: SELECT `comments`.* FROM `comments` RIGHT JOIN (SELECT
I need to write a query that will group a large number of records
I need to write a query that returns all object less that or equal
In SQL one can write a query that searches for a name of a
I'm trying to write a custom SQL query that will create a list of
I have a query that I pulled from ms sql 2000 and plugged into
My question is Write an SQL query that will determine which is the least
I desperately need help with a query that's been causing a lot of grief
I have a text file that include sql queries. Each query ends with ;.

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.